Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
714 views
in Technique[技术] by (71.8m points)

android - Custom AppCompat Theme not changing Overflow icon on older devices

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.

Code

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

Correct icon

enter image description here

Incorrect icon

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...