简体   繁体   中英

Change the action bar settings icon color

How can one change the color of the overflow icon in the action bar?

在此输入图像描述

(The most right icon)

You can use something like this

<style name="MyTheme" parent="android:style/Theme.Holo.Light">
     <item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item>
</style>

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

in your AndroidManifest.xml

<application
    android:theme="@style/MyTheme" >

If you want to change actionBar color @style/MyActionBar

        <!-- Support library compatibility -->
        <item name="actionBarStyle">@style/MyActionBar</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@color/app_theme_color</item>

        <!-- Support library compatibility -->
        <item name="background">@color/app_theme_color</item>
        <item name="android:alwaysDrawnWithCache">true</item>
        <item name="android:displayOptions">showTitle|showHome|homeAsUp</item>
        <item name="android:icon">@android:color/transparent</item>
    </style>

Then in your AndroidManifest.xml you need to refer this one inside your application tag.

    android:theme="@style/CustomActionBarTheme"

If you just want to change the color you can simply tint it:

  <style name="DotsDarkTheme" parent="@style/Widget.AppCompat.ActionButton.Overflow" >
    <item name="android:tint">@color/yourColor</item>
  </style>

and then use it in your style:

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

如果您使用操作栏使用:

        toolbar.getOverflowIcon().setColorFilter(Color.WHITE , PorterDuff.Mode.SRC_ATOP);

It's also worth adding that if you simply want to change the overflow button to a light or dark colour to go with your action bar colour this can be done without specifying a custom icon.

For a dark button colour set your theme as:

<style name="MyTheme" parent="@style/Theme.AppCompat.Light">
    <item name="android:actionBarStyle">@style/MyTheme.ActionBar</item>
</style>

Theme.Holo.Light

For a light button colour add DarkActionBar:

<style name="MyTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MyTheme.ActionBar</item>
</style>

Theme.Holo.Light.DarkActionBar

If, like me, you want a light button colour but you want the overflow menu to be light you can do the following:

<style name="MyTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MyTheme.ActionBar</item>
    <item name="android:actionBarWidgetTheme">@style/MyTheme.ActionBarWidget</item>
</style>
<!-- This helps the PopupMenu stick with Light theme while the ActionBar is in Dark theme -->
<style name="MyTheme.ActionBarWidget"
    parent="android:Theme.Holo.Light">
    <item name="android:popupMenuStyle">@android:style/Widget.Holo.Light.PopupMenu</item>
    <item name="android:dropDownListViewStyle">@android:style/Widget.Holo.Light.ListView.DropDown</item>
</style>

You can use your custom style inside for menu item, like this

<item name="android:itemTextAppearance">@style/myCustomMenuTextApearance</item>

Define the style like this:

<style name="myCustomMenuTextApearance" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
        <item name="android:textColor">@android:color/primary_text_dark</item>
</style>

Also see Change the background color of the options menu and

Android: customize application's menu (eg background color)

Create below style in styles.xml with parent as ActionButton Overflow widget and then use that theme in the style that you are using for that activity where toolbar is shown.

Step-1) Creating style for the actionButtonOverflow

<style name="DotsDarkTheme" parent="@style/Widget.AppCompat.ActionButton.Overflow" >
        <item name="android:tint">your color</item>
</style>

Step-2) Using this style in the activity that is using actionBar

<style name="CustomMainActivityTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="actionOverflowButtonStyle">@style/DotsDarkTheme</item>
</style>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM