如何更改操作栏溢出按钮的颜色

18

首先我已经阅读了在操作栏上更改溢出按钮的颜色,但我无法使其正常工作。

我只想要一个简单的主题:操作栏背景蓝色,按钮和文本为白色。对于我拥有的列表视图,我希望它们是相反的:白色背景和蓝色文本。如果有简单的方法可以实现这一点,请让我知道。 我尝试使用样式设置文本颜色,但我无法使文本和按钮成为不同的颜色,因此我尝试设置溢出可绘制对象进行测试,将点变成红色,但看不到任何效果。

    <!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="actionBarStyle">@style/ActionBarStyle</item>
</style>

<style name="ActionBarStyle" parent="Widget.AppCompat.ActionBar">
    <item name="background">@color/background_blue</item>
    <item name="titleTextStyle">@style/AppTheme.ActionBar.Title</item>
    <item name="actionOverflowButtonStyle">@style/AppTheme.ActionButton.Overflow</item>
</style>

<style name="AppTheme.ActionBar.Title" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">@color/white</item>
</style>

<style name="AppTheme.ActionButton.Overflow"  parent="@style/Widget.AppCompat.ActionButton.Overflow">
    <item name="android:src">@drawable/abc_ic_menu_overflow_button</item>
</style>

我正在测试的溢出按钮: The overflow button that I'm using for testing

而我看到的是:

What I see

显然没有使用红色按钮。

我能够使用android:textColorPrimary属性,但这会产生不良副作用。

    <style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="android:textColorPrimary">@color/white</item>
    <item name="actionBarStyle">@style/ActionBarStyle</item>
</style>

<style name="ActionBarStyle" parent="Widget.AppCompat.ActionBar">
    <item name="background">@color/background_blue</item>
    <item name="titleTextStyle">@style/AppTheme.ActionBar.Title</item>
</style>

<style name="AppTheme.ActionBar.Title" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">@color/white</item>
</style>

在此输入图片描述

但是,由于我希望我的列表具有白色背景,所以有些文本因为文本和背景都是白色而无法看到。

谢谢!


在你的主题中添加 actionOverflowButtonStyle。 - Jay Rathod
哇,如此简单的更改,谢谢! - bitrock
我正在添加这个答案,请接受它,这样其他遇到同样问题的人也可以从中受益。 - Jay Rathod
4个回答

42

我找到了另一种方法来解决这个问题,不需要替换图像!

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="actionBarTheme">@style/AppTheme.ActionBarTheme</item> <!-- used for the back arrow on the action bar -->
</style>

<style name="AppTheme.ActionBarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">
    <!-- THIS is where you can color the arrow and the overflow button! -->
    <item name="colorControlNormal">@color/splash_title</item> <!-- sets the color for the back arrow -->
    <item name="actionOverflowButtonStyle">@style/actionOverflowButtonStyle</item> <!-- sets the style for the overflow button -->
</style>

<!-- This style is where you define the tint color of your overflow menu button -->
<style name="actionOverflowButtonStyle" parent="@style/Widget.AppCompat.ActionButton.Overflow">
    <item name="android:tint">@color/white</item>
</style>

4
如果您至少在编辑过时的答案时给我一些信用就好了。 - Mike Birkhoff
搜索并尝试了其他所有方法好几天,但这个方法有效。 - Code Wiget

25

android:textColorSecondary对我没有作用。 因此,我尝试着给overflow样式添加tint属性:

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

然后在您的样式中使用它:

  <style name="YourDarkAppTheme">

    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>

    ... your appTheme


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


  </style>

(我已经在这个帖子中回答过了:更改操作栏设置图标的颜色。但这是我在谷歌上搜索答案时的第一个结果)


7
有一种简单的方法可以解决这个问题,例如,如果我们想要工具栏图标和标题字母的白色,我们可以这样做:
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/colorPrimary"
    android:theme="@style/MainMenu"
    app:popupTheme="@style/android:Theme.Holo.Light"/>

在 styles.xml 文件中,我们可以这样做:

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

这个 android:textColorSecondary 可以改变工具栏中图标的颜色。


5
在你的主题中添加 actionOverflowButtonStyle。
<style name="AppTheme" parent="Theme.AppCompat.Light">
 <item name="actionBarStyle">@style/ActionBarStyle</item>
 <item name="actionOverflowButtonStyle">@style/AppTheme.ActionButton.Overflow</item>
</style>

完成了。


1
ActionBarStyleAppTheme.ActionButton.Overflow是什么? - testing

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接