【问题标题】:How to style the Action Bar Overflow on devices with a hardware menu button?如何在带有硬件菜单按钮的设备上设置操作栏溢出样式?
【发布时间】:2013-08-21 14:42:56
【问题描述】:

这就是我在股票 android 上设置 Action Bar Overflow 的样式:

<style name="DropDownNav.MyTheme" parent="@android:style/Widget.Holo.Light.Spinner">
    <item name="android:popupBackground">@drawable/menu_dropdown_panel</item>
    <item name="android:dropDownSelector">@drawable/selectable_background</item>
</style>

但指定的自定义选择器不会应用于带有硬件按钮的三星设备上的弹出选项菜单,而是默认为蓝色。

我看到this answer 并尝试申请

<style name="ListPopupWindow.IvuTheme" parent="android:Widget.ListPopupWindow">
    <item name="android:dropDownSelector">@drawable/list_selector_holo_light</item>
    <item name="android:listSelector">@drawable/list_selector_holo_light</item>
</style>

但没有效果。

为了在后面的硬件按钮选项菜单中更改选择器,我需要继承什么样式(以及我的主题中的相应属性是什么)?

感谢您的建议

【问题讨论】:

    标签: android android-actionbar android-theme android-styles android-optionsmenu


    【解决方案1】:

    1) 扩展您的应用程序类

    public class MyApplication extends Application {
    
    @Override
    public void onCreate() {
        super.onCreate();
    
        try {
            ViewConfiguration config = ViewConfiguration.get(this);
            Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
            if(menuKeyField != null) {
                menuKeyField.setAccessible(true);
                menuKeyField.setBoolean(config, false);
                }
            } catch (Exception ex) {
                // Ignore
            }
        }
    }
    

    2) 添加到清单中:

    <application
        ...
        android:name=".MyApplication">
    

    【讨论】:

    • 它正在工作。我在一个真正的应用程序中使用它。减号是不合适的。
    猜你喜欢
    • 1970-01-01
    • 2012-03-06
    • 1970-01-01
    • 2013-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多