Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change actionOverflowButtonStyle with appcompat v21

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

like image 909
Anton Holovin Avatar asked Oct 20 '14 22:10

Anton Holovin


1 Answers

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.

like image 113
Gabriele Mariotti Avatar answered Oct 17 '22 07:10

Gabriele Mariotti