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

标签 android

首先我已经阅读了Change color of the overflow button on action bar但 我无法让它工作。

我只想有一个简单的主题:操作栏背景为蓝色,按钮和文本为白色。对于我拥有的 ListView ,我希望它们是相反的:白色背景和蓝色文本。如果有一种简单的方法可以实现这一点,请告诉我。 我曾尝试使用样式设置文本颜色,但我无法将文本和按钮设置为不同的颜色,因此我尝试设置溢出可绘制对象,出于测试目的,我将这些点设为红色,但没有看到任何效果。

    <!-- 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>

enter image description here

但是由于我想为我的列表使用白色背景,所以我最终无法看到一些文本,因为文本和背景都是白色的。

谢谢!

最佳答案

我找到了另一种不需要替换图像的方法!

<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>

关于android - 如何更改操作栏溢出按钮颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35932669/

相关文章:

Android:手机处于 sleep 状态时GPS位置更新?

java - BroadcastReceiver 未将数据发送回主类

android - 如何在android studio中访问文件资源管理器

android - 预编译的dex库

java - 可热完成长时间运行的任务

android - int数组到android中的opengl纹理

java - Android - ListView 项目样式在滚动时失败

android - 地理围栏、iBeacons 以及在人们走进餐厅时发送通知

java - 安卓多点触控游戏

android - 如何在Listview android中添加第一个字母在右垂直的字母部分索引器