Android MenuItem Get Method for showAsAction

I am looking for a free mentuItem.setShowAsAction () method, i.e. menuItem.getShowAsAction () , since it does not seem to exist.

http://developer.android.com/reference/android/view/MenuItem.html

Since I need to record the current state before setting them to MenuItem.SHOW_AS_ACTION_NEVER, so when the orientation of the device changes to landscape, I can return the menu items to their old state.

I need to do this because Honeycomb does not provide a new line for showing tabs like ICS. Thus, in cells there is not enough space for tabs.

Is there another generic get get method in Java or Android to find a parameter in XML for the showAsAction attribute in menuitem.

thanks

+7
source share
2 answers

I found out that the below class has this isActionButton () method

android.support.v7.internal.view.menu.MenuItemImpl

Note that MenuItem is the interface, not the class from which the intended instance of the menuitem object was created.

If you are using the android.support.v7 compatibility package, simply highlight the menuitem MenuItemImpl object.

This is done as follows:

((MenuItemImpl)item).isActionButton() 
+1
source

You can use this method from what was said in another answer:

 @SuppressLint("RestrictedApi") private int getShowAsActionFlag(MenuItem item) { MenuItemImpl itemImpl = ((MenuItemImpl) item); if (itemImpl.requiresActionButton()) return MenuItemImpl.SHOW_AS_ACTION_ALWAYS; else if (itemImpl.requestsActionButton()) return MenuItemImpl.SHOW_AS_ACTION_IF_ROOM; else if (itemImpl.showsTextAsAction()) return MenuItemImpl.SHOW_AS_ACTION_WITH_TEXT; else return MenuItemImpl.SHOW_AS_ACTION_NEVER; } 
0
source

All Articles