是否可以更改我的主题 (AppCompat) 中的 AppBar 文本颜色?

Is it possible to change AppBar text color in my theme (AppCompat)?

我只想更改 AppBar 文本颜色,但在主题编辑器中(我使用 Android Studio)我只能更改 textColorPrimary(它会更改 AppBar 文本颜色以及 LargeText 颜色).

我当前的主题:

我只能更改 textColorPrimary:

现在我把文字颜色改成这样:

style.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

activity.xml

...
<android.support.design.widget.AppBarLayout
        ...
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
           ...
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

        ...

</android.support.design.widget.AppBarLayout>

是否可以在 style.xml 中更改我的 AppTheme 中的文本颜色?

  1. 创建一个自定义主题 parent 您想要的基本主题, 比如ThemeOverlay.AppCompat.Dark.ActionBar.
  2. 为主题添加自定义。对于标题颜色,它将是 textColorPrimary。对于溢出和图标,它将是 textColorSecondary.

然后使用您创建的自定义主题为您的工具栏设置主题。

@color/colorForeground

您只需在样式中添加“colorForeground”属性即可更改应用栏中的前景色。这也会更改文本颜色和菜单点的颜色。

或者您可以使用主题编辑器来编辑颜色。