更改操作栏标题颜色 Theme.AppCompat.Light.DarkActionBar Android

6

我想在Android中将操作栏标题颜色更改为白色,并且我正在使用值主题Theme.AppCompat.Light和值-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 标题颜色未改变。


你可以在这里找到一些答案。 - kelvincer
3个回答

5

您可以通过使用colorPrimary属性来指定ActionBar的背景颜色,如下所示:

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

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

3
问题是更改文本颜色而不是背景颜色。是的,你可以在AppCompat上设置colorPrimary,类似于Material action bar,但是你不能以同样的方式设置textColorPrimary,这就是他提出问题的原因。 - Jason Hu
1
问题询问如何更改ActionBar文本颜色,而不是ActionBar本身的颜色。 - sahil shekhawat

1
如果你正在使用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"/>

0

您还应该检查一下您的布局 XML 文件,确保没有指定 android:theme 属性,否则它将优先于主题。


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