I am stuck with Menu item visibility in ABS even there are room in header. Thing is I have test in different size of device but in each case i am able to see only one and that is Overflow menu.
I am using onPrepareOptionsMenu
to manage my menu as dynamically and that is working perfectly.(but don't know may be this issue is occur bye onPrepareOptionsMenu
or some other reason).
View Difference:
First Approach I have create menu programmatically and set that visibility using setShowAsAction(). Somewhere i have found setShowAsActionflag() also and i have try that also. But in that case i am not able to see Overflow menu in small screen 320*480
. So, That is my issue in programmatically approach.
Here is my code
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// TODO Auto-generated method stu
// TO Remove older menu otherwise that will apped menu each time.
menu.clear();
menu.add(Menu.NONE, MENU_SEARCH, Menu.NONE, "Search").setIcon(R.drawable.ic_search).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menu.add(Menu.NONE, MENU_SETTING, Menu.NONE, "Settings").setIcon(R.drawable.ic_action_settings)
.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
if (is_session_exist == 1) {
menu.add(Menu.NONE, MENU_CHANGE_LOGIN, Menu.NONE, "Change Login").setIcon(R.drawable.ic_action_add_person)
.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menu.add(Menu.NONE, MENU_LOGOUT, Menu.NONE, "Logout").setIcon(R.drawable.abs__ic_clear)
.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
} else {
menu.add(Menu.NONE, MENU_LOGIN, Menu.NONE, "Login").setIcon(R.drawable.ic_action_add_person)
.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
}
return super.onPrepareOptionsMenu(menu);
}
Second Approach I have create menu using XML folder and set all property in separate file. Now i am inflecting that menu in onPrepareOptionsMenu
but in that case i am only able to see overflow icon in any density screen even i have set the android:showAsAction="ifRoom|withText"
Here is my XML code.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/mainMenu"
android:icon="@drawable/abs__ic_menu_moreoverflow_holo_dark"
android:showAsAction="always">
<menu>
<item
android:id="@+id/menu_search"
android:icon="@drawable/ic_search"
android:showAsAction="ifRoom|withText"
android:title="Search"
android:visible="true"/>
<item
android:id="@+id/menu_login"
android:icon="@drawable/ic_action_add_person"
android:showAsAction="ifRoom|withText"
android:title="Login"
android:visible="true"/>
<item
android:id="@+id/menu_change_login"
android:icon="@drawable/ic_action_add_person"
android:showAsAction="ifRoom|withText"
android:title="Change Login"
android:visible="false"/>
<item
android:id="@+id/menu_setting"
android:icon="@drawable/ic_action_settings"
android:showAsAction="ifRoom|withText"
android:title="Setting"
android:visible="true"/>
<item
android:id="@+id/menu_logout"
android:icon="@drawable/abs__ic_clear"
android:showAsAction="ifRoom|withText"
android:title="Logout"
android:visible="false"/>
</menu>
</item>
</menu>
I am changing menu item in onPrepareOptionsMenu
using setVisible(false/true);
Here some helpful link which i have refer already but issue is not solve yet.
Set android:showAsAction="ifRoom|withText" programmatically
How to add text to icons in ActionBar?
I don't know why i am getting this issue .Your help and effort will definitely appreciate.
Thank you.