自定义 AppCompat 主题不会更改旧设备上的溢出图标 [英] Custom AppCompat Theme not changing Overflow icon on older devices

查看:17
本文介绍了自定义 AppCompat 主题不会更改旧设备上的溢出图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我决定更改我的应用程序上的 Action Overflow Icon.我让它在 Lollipop 设备上工作,但它在我的 Ice Cream Sandwich 和 Kitkat 设备上不起作用.注意:在它不工作的两个设备上,动作溢出图标有 3 个圆点,因此主题将其更改为 Material 版本......只是不是我的版本.

Recently I decided to change the Action Overflow Icon on my app. I got it working on Lollipop devices, but it isn't working on my Ice Cream Sandwich and Kitkat device. Note: on both the devices that it does not work on, the action overflow icon has 3 rounded dots, so the theme is changing it to the Material version....just not my version.

我的问题是我不能让它在旧设备上运行,但它可以在棒棒糖上运行.

My issue is that I cannot get this to work on older devices, but it works on Lollipop.

以前,我必须为每个版本创建单独的主题,但现在不需要了.只推荐一个主题.

Before, I would have had to create separate themes for each version, but now that is not needed. Only one theme is recommended.

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

        <item name="android:actionOverflowButtonStyle">@style/OverflowMenuButton</item>
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <!--<item name="colorPrimaryLight">@color/primary_light</item>-->
        <item name="colorAccent">@color/accent</item>
        <item name="android:textColorPrimaryInverse">@color/primary_text_light</item>
        <item name="android:textColorPrimary">@color/primary_text</item>
        <item name="android:textColorSecondary">@color/secondary_text</item>
        <!--<item name="icons">@color/icons</item>-->
        <item name="divider">@color/divider</item>

    </style>

    <style name="OverflowMenuButton" parent="@style/Widget.AppCompat.ActionButton.Overflow">
        <item name="android:src">@drawable/ic_star_rate_white_18dp</item>
    </style>


</resources>

正确的图标

推荐答案

您正在使用 android:actionOverflowButtonStyle,这是替换框架溢出按钮的正确方法,仅适用于 Lollipop 及更高版本的设备.

You are using android:actionOverflowButtonStyle, which is the correct approach for replacing the framework overflow button, only available on Lollipop and higher devices.

但是,AppCompat 有自己的 actionOverflowButtonStyle 属性 适用于所有 API 7+ 设备 - 您应该使用它代替 android:actionOverflowButtonStyle:

However, AppCompat has its own actionOverflowButtonStyle attribute which works on all API 7+ devices - you should use that in place of android:actionOverflowButtonStyle:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

    <item name="actionOverflowButtonStyle">@style/OverflowMenuButton</item>

    ...

</style>

这篇关于自定义 AppCompat 主题不会更改旧设备上的溢出图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆