【问题标题】:How do I change the Action Bar Overflow button color如何更改操作栏溢出按钮颜色
【发布时间】:2016-03-11 05:08:20
【问题描述】:

首先我读过Change color of the overflow button on action bar 但是 我无法让它工作。

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

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

我用于测试的溢出按钮

当我看到的时候

显然没有使用红色按钮。

我能够使用 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。
  • 哇,这么简单的改变,谢谢!
  • 我将此添加为答案,请接受它,以便其他面临相同问题的人对他们有所帮助。

标签: android


【解决方案1】:

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

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

【讨论】:

  • 如果您在编辑过时的答案时至少感谢我,那就太好了。
  • 搜索并尝试了几天。这行得通。
【解决方案2】:

android:textColorSecondary 对我不起作用。 所以我尝试为溢出样式着色:

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

(我已经在这个帖子中回答了:Change the action bar settings icon color 但这是我在搜索答案时第一次在 Google 上点击)

【讨论】:

    【解决方案3】:

    有一种方法可以更轻松地解决它,例如如果我们想要标题字母和工具栏图标的白色,我们可以这样做:

    <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 改变了工具栏中图标的颜色。

    【讨论】:

      【解决方案4】:

      在您的主题中添加 actionOverflowButtonStyle。

      <style name="AppTheme" parent="Theme.AppCompat.Light">
       <item name="actionBarStyle">@style/ActionBarStyle</item>
       <item name="actionOverflowButtonStyle">@style/AppTheme.ActionButton.Overflow</item>
      </style>
      

      完成了。

      【讨论】:

      • 什么是ActionBarStyleAppTheme.ActionButton.Overflow
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-01
      • 2012-07-10
      • 1970-01-01
      相关资源
      最近更新 更多