Changing overflow icon in the action bar

64,763

Solution 1

You can with a style, but you have to add it to the main Theme declaration.

<resources>
    <!-- Base application theme. -->
    <style name="Your.Theme" parent="@android:style/Theme.Holo">
        <!-- Pointer to Overflow style ***MUST*** go here or it will not work -->
        <item name="android:actionOverflowButtonStyle">@style/OverFlow</item>
    </style>

    <!-- Styles -->
    <style name="OverFlow" parent="@android:style/Widget.Holo.ActionButton.Overflow">
        <item name="android:src">@drawable/ic_action_overflow</item>
    </style>

</resources>

You also can change it dynamically, which I go into detail about here:

Changing the Android Overflow menu icon programmatically

Solution 2

For those who can't get it to work try this WITHOUT the "android:" namespace.

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

Solution 3

  1. Change your custom overflow icon of Actionbar in styles.xml.

     <resources>
        <!-- Base application theme. -->
        <style name=“MyTheme" parent="@android:style/Theme.Holo">
           <!-- Pointer to Overflow style DONT forget! -->
           <item name="android:actionOverflowButtonStyle">@style/MyOverFlow</item>
        </style>
    
        <!-- Styles -->
        <style name="MyOverFlow" parent="@android:style/Widget.Holo.ActionButton.Overflow">
            <item name="android:src">@drawable/ic_your_action_overflow</item>
        </style>
     </resources>
    
  2. Put custom theme "MyTheme" in application tag of AndroidManifest.xml

    <application
        android:name="com.example.android.MainApp"
        android:theme="@style/AppTheme">
    </application>
    

Have fun.@.@

Solution 4

No matter what I tried to do in styles.xml, none of the solutions worked for me. In the end, if you have AppCompat 23+, which you should, this is the easiest way that actually works:

toolbar.setOverflowIcon(drawable);

Solution 5

@adneal's answer is correct (so this is just a community wiki explanation to expand on it).

One of the comments suggested that there may be misunderstanding how to do this, so my answer is just another example on how to override the Overflow icon image.

Code below is based on the template styles from the ADT sample New Android Project. The code comes from the styles.xml file in res/values folder.


<style name="AppBaseTheme" parent="android:Theme.Light">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.

    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">

    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    <item name="android:actionOverflowButtonStyle">@style/OverflowMenuButton</item>
</style>

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

What this above code does is replace the default overflow icon with whatever drawable you have that is named ic_menu_moreoverflow. If you want a quick way to test it out, use your app's launcher icon filename, which will make it obvious how it works.

A useful resource to use when trying to understand ActionBar styling, is:

There you can define specific colours to use for your Overflow icon, and the ZIP file will include the correct styles.xml file for you.

Share:
64,763

Related videos on Youtube

pjanecze
Author by

pjanecze

Senior software engineer @ Polidea Google Play apps

Updated on January 28, 2020

Comments

  • pjanecze
    pjanecze over 4 years

    Is it possible to change the overflow icon in the action bar? I have blue icons for all ActionBar items and I also want to change the overflow icon when it appears.

    • Al Lelopath
      Al Lelopath about 7 years
      @ShirishHerwade: That link is dead now.
  • pjanecze
    pjanecze about 12 years
    I have already found this solution looking into source code, but thanks :) It is a good answer.
  • Richard Le Mesurier
    Richard Le Mesurier over 11 years
    NOTE that this is applied to the THEME, and not the STYLE. Had me stuck for a while until I realised that. Thx @aneal
  • Mr-IDE
    Mr-IDE over 11 years
    This will crash on tablets running Android 3.0 (API 11), because it doesn't like people defining the style "android:actionOverflowButtonStyle" (probably platform bug). So you have to use different styles in values-v11/styles.xml and values-v15/styles.xml.
  • Nick White
    Nick White almost 11 years
    And for ActionBarSherlock users, the parent style is: parent="Widget.Sherlock.ActionButton.Overflow"
  • Richard Le Mesurier
    Richard Le Mesurier over 9 years
    @BillMote TBH its not making sense to me either after 2 years?! I can see I upvoted adneal at the time, so he definitely helped me. I must have been reading other posts that said something else, in order to have felt like that comment meant something. Sorry I must plead the 5th, and say that maybe it meant something at the time to have received +5. Then again, votes don't count for much around here. I'm posting (as an answer) minimal code from a production app that might help.
  • Bill Mote
    Bill Mote over 9 years
    @RichardLeMesurier I figured it out. You have to include the reference to the overflow menu icon where you are declaring your theme rather than with the rest of the styles -- even the ones related to your actionbar. Simply moving it to the "Theme" section of your styles fixes the issue of it not working. That cost me a couple of hours today. I updated the answer to make it more clear.
  • Richard Le Mesurier
    Richard Le Mesurier over 9 years
    @BillMote so glad to hear I was making sense back in the day, even if I couldn't explain it today! Good on you for clarifying things by updating the answer.
  • fattire
    fattire over 9 years
    For appcompat (v21 lollipop anyway), parent="@style/Widget.AppCompat.ActionButton.Overflow" seems to work for me.
  • DaMachk
    DaMachk about 9 years
    Thanks mate, this really helped. Anyone got an explanation for this?
  • matiash
    matiash almost 9 years
    @DaMachk If you're using AppCompat, then don't include the "android:" namespace.
  • Shubhamhackz
    Shubhamhackz over 5 years
    Most accurate way that i have found!