【问题标题】:Overflow menu icon color won't change for android < 21android < 21 的溢出菜单图标颜色不会改变
【发布时间】:2016-04-25 15:07:31
【问题描述】:

我正在尝试更改工具栏的溢出菜单图标颜色,如下所示:-

<android.support.v7.widget.Toolbar 
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:id="@+id/toolbar_actionbar"
  android:layout_width="match_parent"
  android:layout_height="?attr/actionBarSize"
  app:layout_scrollFlags="scroll|enterAlways"
  app:popupTheme="@style/CustomPopup"
  app:theme="@style/MyCustomToolBarTheme">    
</android.support.v7.widget.Toolbar>

两个自定义主题:-

<style name="MyCustomToolBarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
        <item name="android:textColorSecondary">@android:color/white</item>
</style>
<style name="CustomPopup" parent="ThemeOverlay.AppCompat.Light">
        <item name="android:textColorSecondary">@android:color/white</item>
</style>

我也可以更改标题/菜单图标颜色。 但是溢出的图标颜色总是黑色。我什至尝试指定自定义图标也不起作用。

【问题讨论】:

  • 图标颜色由colorControlNormal 定义,所以覆盖它。 (它在深色主题中指向 android:textColorPrimary,在浅色主题中指向 android:textColorSecondary。)

标签: android android-xml android-toolbar android-styles


【解决方案1】:

你可以试试下一个:

    public static void setOverflowButtonColor(final Toolbar toolbar, final int color) {
    Drawable drawable = toolbar.getOverflowIcon();
    if(drawable != null) {
        drawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(drawable.mutate(), color);
        toolbar.setOverflowIcon(drawable);
    }
}

【讨论】:

    【解决方案2】:

    我通过用自己的图标替换溢出图标并自己设置其颜色解决了这个问题。

    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="actionOverflowButtonStyle">@style/OverflowMenuButton</item>
    </style>
    
    
    <style name="OverflowMenuButton" parent="Theme.AppCompat.NoActionBar" >
        <item name="android:src">@drawable/overflow</item>
    </style>
    

    【讨论】:

    • 我尝试过以同样的方式更改图标,但没有成功
    【解决方案3】:

    将您的父级从“ThemeOverlay.AppCompat.Light”更改为“Theme.AppCompat.Light”。

    <style name="ToolbarOverflow" parent="Theme.AppCompat.Light">
        <item name="android:textColorSecondary">@color/white</item>
    </style>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-30
      • 1970-01-01
      • 2015-07-11
      • 1970-01-01
      相关资源
      最近更新 更多