I'm using actionbarsherlock library, activity has flag android:uiOptions="splitActionBarWhenNarrow", so ActionBar's items are in the bottom of screen
the items are described in the xml file
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_0"
android:title="#string/action_0"
android:showAsAction="always"/>
<item android:id="#+id/menu_1"
android:title="#string/action_1"
android:showAsAction="always"/>
<item android:id="#+id/menu_2"
android:title="#string/action_2"
android:showAsAction="always"/>
</menu>
I'm inflating menu
public boolean onCreateOptionsMenu(Menu menu) {
menu.clear();
MenuInflater supportMenuInflater = getSupportMenuInflater();
supportMenuInflater.inflate(R.menu.inbox_conversation, menu);
return super.onCreateOptionsMenu(menu);
}
after, on devices with android 2.3, menu items do not have the same weight
first two options take about 80% percents of action bar & the latest takes only 20%, so they are not aligned properly & don't take equal space.
Don't know what to do. Any suggestions?
Many thanks!
might want to try adding layout-weight in item tag in xml
<item
android:id="#+id/menu_0"
android:title="#string/action_0"
android:showAsAction="always"
android:layout_width="wrap_content"
android:layout_weight="1" >
</item>
Related
Hello
I'm trying to add 2 menu items in the action bar. On the designer they look ok, but when I run the application, both menu items goes in the dropdown list hamburger menu (there's enough "room" to display on the action bar).
I tried to replace app:showAsAction to android:showAsAction, doesn't work this replacement.
this is my menu_main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.tabdemo.MainActivity">
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title=""
app:showAsAction="never"
/>
<item
android:id="#+id/userMenu"
android:title="User"
app:showAsAction="ifRoom" />
<item
android:id="#+id/logoutMenu"
android:icon="#drawable/opendoorlogo2"
android:title="Logout"
app:showAsAction="ifRoom" />
And this is the java code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
MenuItem userMenuItem = menu.findItem(R.id.userMenu);
userMenuItem.setTitle(username);// global string
MenuItem logoutMenuItem = menu.findItem(R.id.logoutMenu);
logoutMenuItem.setIcon(R.drawable.opendoorlogo2);
return true;
}
Thanks in advance (P.S. Logo doesn't load on Logout menu Item)
First of all make sure your drawable file is not too big for the actionbar, if so you can convert it to actionbar icon size.
https://romannurik.github.io/AndroidAssetStudio/icons-actionbar.html#source.space.trim=1&source.space.pad=0&name=ic_action_example&theme=light&color=33b5e5%2C60
android:showAsAction="always"
if this doesn't help you.
Best way is to create a custom actionbar layout and place your icon over there instead of adding it as Menus.
I have a action bar set up as this:
When I click on it a settings popup appears like this which when pressed takes me to my apps settings page.
My question is how would I remove the settings popup so that it takes me directly to my settings activity when I press the three dotted button? I tried playing around with code below but it yielded no result.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
Goto the menu folder of your project. res>>menu and find the xml file representing the
You have to add the android:showAsAction="always" like below:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu"
android:title="#string/menu_settings_item"
android:showAsAction="always"
android:icon="#android:drawable/ic_menu_a" />
</menu>
Use the showAsAction parameter.
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu"
android:title="#string/menu_settings_item"
android:showAsAction="always"
android:icon="#android:drawable/ic_menu_a" />
</menu>
You can specify that your settings option always appears as a button on the action bar. You don't need the three dots in this case.
For instance, you can specify your action bar menu item like this (notice the "always" value):
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:icon="#drawable/ic_action_settings"
android:showAsAction="always" />
Please..please help!
I'm new with android development. After i create an app with simple menu. i click on the parent menu, i don't see the items in the submenu appeared. I don't know why is that. Enyone know this, please teach me.
i use nexus Emulator to show result. (nesux S (4.0", 480 X 800:ddpi)
create menu in the Menu folder -> menu-demo like:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/addnew" android:title="add new">
<menu>
<item android:id="#+id/name" android:title="add name"></item>
<item android:id="#+id/age" android:title="Add age"></item>
</menu>
</item>
<item android:id="#+id/update" android:title="update"></item>
<item android:id="#+id/delete" android:title="delete"></item>
</menu>
i update Mainactivity.java in the src.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_demo, menu);
return true;
}
You're missing android:showAsAction="[property".
You can use a few parameters for showAsAction, such as always, never, and ifRoom.
Add these properties to your code, so for example, a menu item that I always want to appear on the actionbar would be like
<item
android:id="#+id/test"
android:showAsAction="always"
android:title="test" >
</item
For submenus, you basically want the topmost selection shown as an action always and the submenu shown never.
I am currently having an issue showing the option menu items on the actionbar. For some reason, the items only show on the overflow menu and this is true for post ICS devices as well. I am using the v7-appcompat library to support sdks from version 8 onwards.
In the main activity I have:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.wild_news, menu);
return true;
}
My menu items are defined as follow:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
**xmlns:app="http://schemas.android.com/apk/res-auto"** >
<item
android:id="#+id/menu_refresh"
android:icon="#drawable/ic_action_refresh"
**app:showAsAction="always"**
android:title="#string/menuTitle_refresh"/>
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
**app:showAsAction="ifRoom"**
android:title="#string/action_settings"/>
I also have a spinner in the actionbar with the following xml layout:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:minWidth="140dp"
android:layout_gravity="center_vertical"
style="#style/ActionBarNavListTitle" />
I can't seem to get my head around it.
Great I found the issue to be related to a mismatch in the ActionBar style definition which I have resolved now:
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
I have an ActionBar that should display the action buttons in a custom way. For this I created a custom view and attached it to the ActionBar.
One thing to mention is that I am using a menu.xml resoure file to load the options menu and display them on a smartphone, but do not display them on tablet, instead use a custom view. For this I market every menu item in the xml as: android:showAsAction="never"
Everything looks fine, except one little thing that still remains on the right of the ActionBar - the "More" button.
How can I remove it?
I tried this:
ActionBar bar = activity.getActionBar();
bar.removeAllTabs();
but the "more" button still remains there.
EDIT:
This is my menu.xml file:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_username"
android:icon="#drawable/menu_username"
android:orderInCategory="0"
android:showAsAction="never"
android:title="#string/menu_username">
<menu>
<item
android:id="#+id/menu_logout"
android:title="#string/menu_logout"/>
</menu>
</item>
<item
android:id="#+id/menu_settings"
android:icon="#drawable/menu_settings"
android:orderInCategory="1"
android:showAsAction="never"
android:title="#string/menu_settings"/>
<item
android:id="#+id/menu_search"
android:icon="#drawable/menu_search"
android:orderInCategory="1"
android:showAsAction="never"
android:title="#string/menu_search"/>
</menu>
Please note I still want to inflate this menu on a smartphone, but don't want to use it on a tablet.
Setting showAsAction="never" will force an menu item into the overflow. Why not check in onCreateOptionsMenu(...) that the device is a tablet, and if it is just not inflate the menu? Something like this:
public boolean onCreateOptionsMenu(Menu menu) {
if (getResources().getConfiguration().smallestScreenWidthDp >= 600) {
//It's a tablet, don't inflate, only create the manual view
manualMenuCreation();
} else {
getMenuInflater().inflate(R.menu.menu, menu);
}
return true;
}
Don't forget smallestScreenWidthDp is only available in 3.2 or above, so you'll have to take that into consideration.