Android常量值到常量名称(app :showAsAction ="2")

标签 android xml

我有一些反编译的代码,我正试图找出与常量值一起出现的常量名称。在我的一个 xml 文件中,我看到 app:showAsAction="2"。看起来,according android , 这可以取值 "ifRoom"| “从不” | “withText” | “总是” | "collapseActionView" 但是我怎么才能知道是哪一个呢?有时我可以在网上找到对常量值名称映射的引用,但有时我找不到。有办法确定吗?

<?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>

最佳答案

当然可以,

你需要查看android.view.MenuItem的源码。那里定义了许多常量,包括您需要的常量。

public static final int SHOW_AS_ACTION_ALWAYS = 2;

这是android.view.MenuItem界面的源码,

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链接到 MenuItem 类的源代码

关于Android常量值到常量名称(app :showAsAction ="2"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39292561/

相关文章:

android - 从快捷方式启动 Activity 总是同时启动主 Activity

android studio 错误 : app-release-unsgined. apk 未签名

android - 如何在 map 上显示带有地址的开始-目的地屏幕

java - XMLUnit-2 忽略某些嵌套的 XML 元素

android - 更改 android :hint to android:text 时,Android editText 中不显示文本

在 android Kitkat 中找不到 android.support.v4.content.FileProvider 类

android - 请配置Android SDK Android Studio

java - Spring ClassPathXmlApplicationContext 空指针异常

xml - 有没有办法使用 XPath 或 XQuery 在 SoapUI 中测试无序 XML 标记中的值?

c# - C# 中将具有相同架构的 2 个以上 xml 文件合并在一起的最有效方法是什么?