【问题标题】:change action bar title color Theme.AppCompat.Light.DarkActionBar android更改操作栏标题颜色 Theme.AppCompat.Light.DarkActionBar android
【发布时间】:2024-11-25 16:30:02
【问题描述】:

我想在 android 中将操作栏标题颜色更改为白色。我在值 Theme.AppCompat.Light 和 values-14 Theme.AppCompat.Light.DarkActionBar 中使用主题
到目前为止我已经尝试过 在值文件夹中:

<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:textColor">@android:color/white</item>
</style>

和值 -14 文件夹

  <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<!-- ActionBar styles -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:textColor">@android:color/white</item>
</style>

但 ActionBar 标题颜色没有改变。

【问题讨论】:

  • 你可以找到一些答案here

标签: android android-actionbar


【解决方案1】:

您可以使用colorPrimary 属性指定ActionBar 的背景颜色;类似于以下内容:

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

以上是为AppCompat创建的特殊标签;您会注意到 android: 命名空间被省略了。

【讨论】:

  • 问题是改变文本颜色而不是背景颜色。是的,您可以在 AppCompat 上设置 colorPrimary 类似于 Material 操作栏,但您不能在同一方面设置 textColorPrimary,这就是他问这个问题的原因。
  • 问题要求改变actionbar文本颜色的方法,而不是action bar本身的颜色。
【解决方案2】:

如果你使用 Theme.AppCompat.Light.NoActionBar 做

<android.support.v7.widget.Toolbar  xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="@color/background_material_dark"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

【讨论】:

    【解决方案3】:

    您还应该检查您的布局 xml 文件中是否没有指定 android:theme 属性,该属性优先于主题

    【讨论】:

      最近更新 更多