AppCompat Toolbar: Change Overflow Icon Color in ActionMode

前端 未结 12 760
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-31 03:12

With the AppCompat Toolbar, I want to be able to change the color of the overflow menu icon on ActionMode change.

For example, the overflow icon will be white in normal

相关标签:
12条回答
  • 2021-01-31 03:47
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="actionOverflowButtonStyle">@style/CustomOverflowButtonStyle</item>
    </style>
    <style name="CustomOverflowButtonStyle" parent="Widget.AppCompat.ActionButton.Overflow">
        <item name="android:tint">@color/black</item>
    </style>
    
    0 讨论(0)
  • 2021-01-31 03:48

    Add this code on your res->styles.xml

    <style name="ToolbarColored" parent="AppTheme">
    <item name="android:textColorSecondary">YOUR_COLOR</item>
    </style>
    

    Then your 'ToolbarColored' style in your XCML file like belove

    <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            app:theme="@style/ToolbarColored"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />
    
    0 讨论(0)
  • 2021-01-31 03:48
    <style name="ToolBarTheme" parent="ThemeOverlay.AppCompat.ActionBar">
        <item name="android:tint">@color/colorAccent</item>
    

    create the above theme.set tint with your color and add this theme to the toolbar.

    <androidx.appcompat.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="?attr/actionBarSize"
            android:theme="@style/ToolBarTheme"/>
    
    0 讨论(0)
  • 2021-01-31 03:50
    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
         <item name="android:actionOverflowButtonStyle">@style/ActionButton.Overflow.Icon</item>
     </style>
    
     <style name="ActionButton.Overflow.Icon" parent="android:style/Widget.Holo.Light.ActionButton.Overflow">
         <item name="android:src">@mipmap/yourwanticon</item>
     </style>
    
    0 讨论(0)
  • 2021-01-31 03:54

    If you want the white overflow menu icon simply add android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" to your Toolbar layout code.

    If you want the dark overflow menu icon use android:theme="@style/Base.Widget.AppCompat.Light.PopupMenu"

    So final code is something like:

    <android.support.v7.widget.Toolbar
            android:id="@+id/a_main_tb"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"
            android:background="@color/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:title="@string/app_name"
            app:titleTextColor="#ffffff"
            />
    

    Also, you should understand that it will change the color of the menu items also.

    0 讨论(0)
  • 2021-01-31 03:55

    To correctly change the color of your toolbar's overflow menu icon, set your toolbar's theme to an AppCompat dark ActionBar theme. For example:

    In your res/values/style.xml file create a theme that inherits from AppCompat in this manner:

    <style name="AppTheme.MyThemeName" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    

    Now set your toolbar's theme to this theme:

    <android.support.v7.widget.Toolbar
      android:id="+id/my_toolbar_id
      android:layout_width="match_parent"
      android:layout_height="@dimen/my_toolbar_height"
      android:theme="@style/AppTheme.MyThemeName">
    
    </android.support.v7.widget.Toolbar>
    
    0 讨论(0)
提交回复
热议问题