I made an Navigation-Drawer on the left and a menu on the right but my menu on the right (3 dots menu) is over the blue line...
I had the same problem with my Title text-view but i simply made his background-color transparent to fix it. Sadly i haven't been able to do the same with my menu.
Is there a way to make my menu background transparent or a work around to make my blue line go over it?
Here is how i made my menu:
MainActivity
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_view, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
// toggle nav drawer on selecting action bar app icon/title
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Menu options
switch (item.getItemId()) {
case R.id.map_view:
Toast.makeText(getApplicationContext(), "Map view pressed",
Toast.LENGTH_LONG).show();
//startActivity(GoogleMapsActivity.class);
return true;
case R.id.infrastucture_only:
Toast.makeText(getApplicationContext(),
"Infrastucture only pressed", Toast.LENGTH_LONG).show();
return true;
case R.id.infrastucture_map:
Toast.makeText(getApplicationContext(),
"Infrastucture + map pressed", Toast.LENGTH_LONG).show();
return true;
case R.id.camera_only:
Toast.makeText(getApplicationContext(), "Camera only pressed",
Toast.LENGTH_LONG).show();
return true;
case R.id.camera_infrastucture:
Toast.makeText(getApplicationContext(),
"Infrastucture + Camera pressed", Toast.LENGTH_LONG).show();
//startActivity(MetaioActivity.class);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
menu_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/dots_menu"
android:icon="#drawable/ic_action_overflow"
android:showAsAction="always"
android:title="#string/dots_menu">
<menu>
<item
android:id="#+id/map_view"
android:icon="#drawable/ic_action_map"
android:showAsAction="never"
android:title="#string/map"/>
<item
android:id="#+id/infrastucture_only"
android:showAsAction="never"
android:title="#string/infrastucture_only"/>
<item
android:id="#+id/infrastucture_map"
android:showAsAction="never"
android:title="#string/infrastucture_map"/>
<item
android:id="#+id/camera_only"
android:showAsAction="never"
android:title="#string/camera_only"/>
<item
android:id="#+id/camera_infrastucture"
android:showAsAction="never"
android:enabled="false"
android:title="#string/camera_infrastucture"/>
</menu>
</item>
</menu>
Thank you :)
I fixed the problem. I forgot to go to my style.xml file and add the transparency to my custom style like this:
<style name="MyActionBarStyle" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:icon">#android:color/transparent</item>
<item name="android:background">#android:color/transparent</item>
</style>
Now i don't know why when i open the menu it's not transparent
http://i821.photobucket.com/albums/zz140/miguel_melo_43/openWindow_zpse164f5b7.png
Is there a better way to make the menu so i can customize like i did with my navigation drawer?
http://i821.photobucket.com/albums/zz140/miguel_melo_43/NavDrawer_zpscaf04f64.png
Related
Hello guys i want to display action with text and images on action bar, but i only get text in overflow menu
my menu.xml file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/action_show_ir_list"
android:showAsAction="ifRoom"
android:title="Cancel"/>
<item
android:id="#+id/phone"
android:title="Wowio"
android:icon="#drawable/logo"
android:showAsAction="ifRoom"
/>
<!--android:icon="#drawable/info"-->
<item
android:id="#+id/computer"
android:title="Done"
android:showAsAction="ifRoom"
/>
</menu>
in my main class
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch(item.getItemId()){
case R.id.phone:
Toast.makeText(getBaseContext(), "You selected About App", Toast.LENGTH_SHORT).show();
break;
case R.id.computer:
Toast.makeText(getBaseContext(), "You selected About Developer", Toast.LENGTH_SHORT).show();
break;
case R.id.action_show_ir_list:
Toast.makeText(getBaseContext(), "Volume Set To Max", Toast.LENGTH_SHORT).show();
break;
}
return true;
}
Here every thing is coming in over flow menu nothing is coming on action bar
I tried every thing on internet and nothing is working
What should i do to show them on ActionBar?
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:[yourapp]="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/menu_add_size"
android:title="#string/menu_add_item"
android:orderInCategory="10"
[yourapp]:showAsAction="always"
android:icon="#android:drawable/ic_menu_add" />
instead of [yourapp] type your app name
I tried my level of best but I couldnt find it.I am working in navigation drawer activty where I can see a overflow Icon in top right when I click it, a Settings button like thing pops out when I click it(Settings) nothing happens
I dont no how to assing an XML to this so that when it is clicked a new activty should open
I know to create an xml and also to assign a onClickListner to the button but i am unable to proceed further since I dont no where to call the setting activty when that button(Settings button in overflow Icon) is pressed
Try this -
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_settings) {
Intent intent = new Intent(this, YourSettingfActivity.class);
startActivity(intent);
}
return super.onOptionsItemSelected(item);
}
menu_main.xml -
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
android:showAsAction="never"/>
</menu>
You can use find these below methods in activity and there you can inflate the menu and do want you want
Menu xml file
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
>
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
android:showAsAction="never"/>
<item android:id="#+id/action_search"
android:title="#string/action_settings"
android:orderInCategory="100"
android:showAsAction="never"/>
<item android:id="#+id/action_logout"
android:title="#string/action_settings"
android:orderInCategory="100"
android:showAsAction="never"/>
</menu>
and you have to write the code like below in your activity
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings:
Toast.makeText(this, "Settings", Toast.LENGTH_SHORT).show();
return true;
case R.id.item2:
Toast.makeText(this, "Search", Toast.LENGTH_SHORT).show();
return true;
case R.id.action_search:
Toast.makeText(this, "Logout", Toast.LENGTH_SHORT).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Im building my top menu using the following code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.menu_view, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.map_view:
Toast.makeText(getApplicationContext(), "Map view pressed",
Toast.LENGTH_LONG).show();
return true;
case R.id.camera_only:
Toast.makeText(getApplicationContext(), "Camera only pressed",
Toast.LENGTH_LONG).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
menu_view.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/dots_menu"
android:icon="#drawable/ic_action_overflow"
android:showAsAction="always"
android:title="#string/dots_menu">
<menu>
<item
android:id="#+id/map_view"
android:icon="#drawable/ic_action_map"
android:showAsAction="never"
android:title="#string/map" />
<item
android:id="#+id/camera_only"
android:showAsAction="never"
android:title="#string/camera_only"/>
</menu>
</item>
</menu>
It happens that in my main activity i want to use this menu on top, but the menu appers transparent. Im using a fragment to display a full-screen map (google maps api v2), but then i can see the map under the top menu. I would like this fragment to "auto-resize" under the menu.
How can i set menu always on top of every activity?
So, i found out what my problem was!
in styles.xml file:
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo">
<item name="android:windowActionBarOverlay">true</item>
</style> </resources>
i just needed to change the attribute windowActionBarOverlay to false, and it makes automatically the resize for the activity content.
For more details, here is the documentation
I can't get the Action Bar to display my action items. They all show up in the overflow menu. I have pasted all the relevant code below. Can anyone see my problem?
From Activity:
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater mi = getMenuInflater();
mi.inflate(R.menu.viewer_menu, menu);
return true;
}
#Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_download:
return true;
case R.id.menu_star:
return true;
case R.id.menu_report:
return true;
case android.R.id.home:
// app icon in action bar clicked; go home
finish();
return true;
}
return false;
}
From Manifest:
<activity android:name=".CustomActivity"
android:label="">
From values-v11 folder (themes.xml)
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo">
</style>
from menu folder (viewer_menu.xml)
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_download"
android:title="Download" showAsAction="withText"
android:orderInCategory="2"/>
<item android:id="#+id/menu_star"
android:icon="#android:drawable/ic_menu_upload"
android:title="Star"
showAsAction="always"
android:orderInCategory="1"/>
<item android:id="#+id/menu_report"
android:title="Report Problem" showAsAction="always"
android:orderInCategory="0"/>
</menu>
It is android:showAsAction, not just showAsAction.
If you are using support package (android.support.v7.app.ActionBarActivity), you have to use something like this:
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/menu_download"
android:title="Download"
app:showAsAction="withText"
android:orderInCategory="2"/>
<item android:id="#+id/menu_star"
android:icon="#android:drawable/ic_menu_upload"
android:title="Star"
app:showAsAction="always"
android:orderInCategory="1"/>
<item android:id="#+id/menu_report"
android:title="Report Problem"
app:showAsAction="always"
android:orderInCategory="0"/>
</menu>
what version is the android emulator you are running?
Also, have you tried the http://actionbarsherlock.com/ version yet?
I feel this may be a stupid question but I have no idea what to do.
I have a menu which works correctly. One of the items in the menu: "Search" brings up a submenu with different items like "Restaurant", "Cafe", etc.
Below is the XML code for creating the menu and sub menu:
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/new_entry"
android:title="#string/new_entry"
android:icon="#drawable/add_new">
</item>
<item android:id="#+id/search"
android:title="#string/search"
android:icon="#drawable/search">
<menu>
<item android:id="#+id/five"
android:title="#string/five">
</item>
<item android:id="#+id/ten"
android:title="#string/ten">
</item>
<item android:id="#+id/fifteen"
android:title="#string/fifteen">
</item>
<item android:id="#+id/restaurant"
android:title="#string/restaurant">
</item>
<item android:id="#+id/cafe"
android:title="#string/cafe">
</item>
<item android:id="#+id/sandwich"
android:title="#string/sandwich">
</item>
</menu>
</item>
<item android:id="#+id/info"
android:title="#string/info_short"
android:icon="#drawable/info">
</item>
Then in my Activity Class I have:
// Initialise Menu.
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_services, menu);
return true;
}
and:
// Create cases for each menu selection.
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.new_entry:
createFood();
return true;
case R.id.search:
return true;
case R.id.cafe:
Log.d(TAG, "In Cafe SubMenu");
Toast.makeText(getApplicationContext(), TAG, Toast.LENGTH_SHORT);
return true;
case R.id.info:
info();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Each case in "onOptionsItemSelected" does what it is supposed to do, except "case R.id.cafe:" which is the submenu. Here it should post to the LogCat and a Toast for testing but does neither.
What am I missing?
Thanks
I have tried your code and it is working perfectly. Only the Toast is not displaying when I select 'cafe'. That is because, you did not call show() in your code. Your code is
Toast.makeText(getApplicationContext(), TAG, Toast.LENGTH_SHORT);
to show the toast on run time it should call as follows
Toast.makeText(getApplicationContext(), TAG, Toast.LENGTH_SHORT).show();
:)
I think you should remove following lines:
case R.id.search:
return true;