Change actionOverflowButtonStyle with appcompat v21
I

1

8

I want to change the action overflow button icon in my Toolbar (or ActionBar, not matter).

So I go this way:

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:actionOverflowButtonStyle">@style/AppTheme.OverflowButtonStyle</item>
</style>

<style name="AppTheme.OverflowButtonStyle" parent="Widget.AppCompat.Light.ActionButton.Overflow">
    <item name="android:src">@drawable/ic_custom</item>
</style>

or this way:

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="toolbarStyle">@style/AppTheme.ToolbarStyle</item>
</style>

<style name="AppTheme.ToolbarStyle" parent="Base.Widget.AppCompat.Toolbar">
    <item name="actionOverflowButtonStyle">@style/AppTheme.OverflowButtonStyle</item>
</style>

<style name="AppTheme.OverflowButtonStyle" parent="Widget.AppCompat.Light.ActionButton.Overflow">
    <item name="android:src">@drawable/ic_custom</item>
</style>

But both ways don't work. What's wrong there?

And the second question is can I change one resourse from library to another resource from library (I just want to change black action overflow button to white, which presents in the library too).

Interstratify answered 20/10, 2014 at 22:22 Comment(0)
S
25

You can define the overflow icon in the app theme using the actionOverflowButtonStyle attribute.

With a Material Components Theme:

<style name="AppTheme.Base" parent="Theme.MaterialComponents.DayNight">
    <item name="actionOverflowButtonStyle">@style/OverFlow</item>
</style>

<style name="OverFlow" parent="Widget.AppCompat.ActionButton.Overflow">
    <item name="srcCompat">@drawable/my_overflow_menu</item>
</style>

With an AppCompat Theme:

<style name="AppTheme" parent="Theme.AppCompat.Light">  
   <item name="actionOverflowButtonStyle">@style/OverFlow</item>
</style>

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

With appcompat you have to use the attributes without the android namaspace.

Snoop answered 21/10, 2014 at 6:13 Comment(6)
Thank you! It works. Do we need to use it twice? I mean <item name="actionOverflowButtonStyle">@style/OverFlow</item> AND <item name="android:actionOverflowButtonStyle">@style/OverFlow</item>. Also is it possible to use resource from library? I cannot find two variants of the overflow button. But library contains black and white, isn't it?Interstratify
You can find the icon also in the new icon set google.com/design/spec/resources/…. Check the answer if it can be useful for other users.Snoop
I am using my theme with parent="@style/Theme.AppCompat.Light.DarkActionBar" and overriding OverFlow button has no effect :(Asafoetida
the "without android namespace" did it for me!Geostrophic
Can you just change the color, not the icon?Testicle
You can change the color by applying a tint: <style name="actionOverflowButtonStyle" parent="@style/Widget.AppCompat.ActionButton.Overflow"> <item name="tint">@color/White</item> </style>Esteresterase

© 2022 - 2024 — McMap. All rights reserved.