Change the action bar settings icon color

后端 未结 6 2068
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-14 08:07

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

\"enter

(

相关标签:
6条回答
  • 2020-12-14 08:10

    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"
    
    0 讨论(0)
  • 2020-12-14 08:13

    if you are using action bar use :

            toolbar.getOverflowIcon().setColorFilter(Color.WHITE , PorterDuff.Mode.SRC_ATOP);
    
    0 讨论(0)
  • 2020-12-14 08:21

    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>
    
    0 讨论(0)
  • 2020-12-14 08:22

    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 (e.g background color)

    0 讨论(0)
  • 2020-12-14 08:24

    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>
    
    0 讨论(0)
  • 2020-12-14 08:34

    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>
    
    0 讨论(0)
提交回复
热议问题