2016-09-02 2 views
3

디 컴파일 된 코드가 있는데 상수 값과 함께 사용되는 상수 이름을 알아 내려고합니다. 내 XML 파일 중 하나에서 app:showAsAction="2"을 참조하십시오. 모양은 according android입니다.이 값을 취할 수 있습니다 "ifRoom" | "never" | "withText" | "always" | "collapseActionView"하지만 어떻게 알아낼 수 있습니까? 때로는 온라인 상수 값 매핑에 대한 참조를 찾을 수 있지만 때로는 그럴 수 없습니다. 확실히 알아낼 방법이 있습니까? 당신이 할 수 물론상수 이름에 대한 Android 상수 값 (app : showAsAction = "2")

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

답변

3

당신은 android.view.MenuItem의 소스에서 볼 필요가있다. 필요한 상수를 포함하여 많은 상수가 정의되어 있습니다. 이 android.view.MenuItem 인터페이스의 소스

public static final int SHOW_AS_ACTION_ALWAYS = 2; 

,

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; 


    ... 
} 

ThisMenuItem 클래스의 소스 코드에 대한 링크입니다