natsuki_1996 natsuki_1996 - 1 month ago 7x
Android Question

Android constant value to constant name (app:showAsAction="2")

I've got some code I decompiled and I'm trying to figure out the constant names that go along with the constant values. In one of my xml files I see

. Looks like, according android, this can take values
"ifRoom" | "never" | "withText" | "always" | "collapseActionView"
But how can I figure out which one? Sometimes I can find reference to the constant value-name mappings online but sometimes I cannot. Is there a way to find out for sure?

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="" xmlns:app="">
<item android:icon="@drawable/my_drawable" android:enabled="false" android:title="my title" app:showAsAction="2"></item>


Sure you can,

You need to look at the source of android.view.MenuItem. There are many constants defined there, including the one you need.

public static final int SHOW_AS_ACTION_ALWAYS = 2;

This is the source of android.view.MenuItem interface,

public interface MenuItem {
     * These should be kept in sync with attrs.xml enum constants for showAsAction
    /** Never show this item as a button in an Action Bar. */
    public static final int SHOW_AS_ACTION_NEVER = 0;
    /** Show this item as a button in an Action Bar if the system decides there is room for it. */
    public static final int SHOW_AS_ACTION_IF_ROOM = 1;
     * Always show this item as a button in an Action Bar.
     * Use sparingly! If too many items are set to always show in the Action Bar it can
     * crowd the Action Bar and degrade the user experience on devices with smaller screens.
     * A good rule of thumb is to have no more than 2 items set to always show at a time.
    public static final int SHOW_AS_ACTION_ALWAYS = 2;

     * When this item is in the action bar, always show it with a text label even if
     * it also has an icon specified.
    public static final int SHOW_AS_ACTION_WITH_TEXT = 4;

     * This item's action view collapses to a normal menu item.
     * When expanded, the action view temporarily takes over
     * a larger segment of its container.
    public static final int SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW = 8;


This is link to the source code of MenuItem class