如何在 Pre-Lollipop 版本中更改工具栏文本颜色

How to change Toolbar Text Color in Pre-Lollipop versions

在 Lollipop 版本中,我的工具栏文本颜色是白色,但是当我 运行 我的应用程序在棒棒糖之前的设备上显示黑色而不是白色时...

styles.xml:-

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

        <item name="colorPrimary">@color/ColorPrimary</item>
        <item name="colorPrimaryDark">@color/ColorPrimaryDark</item>

    </style>

工具栏:

<android.support.v7.widget.Toolbar
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:background="@color/ColorPrimary"
    android:elevation="2dp"
    android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
    xmlns:android="http://schemas.android.com/apk/res/android" />

使用以下

toolbarView.setTitleTextColor (toolbarTextColor);

您可以将主题 Theme.AppCompat.Light.NoActionBar 更改为 Theme.AppCompat.NoActionBar

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorPrimary">@color/primary</item>
        <item name="colorControlNormal">@color/primary_light</item>
        <item name="colorControlActivated">@color/primary</item>
        <item name="colorControlHighlight">@color/primary_dark</item>
    </style>

或 将项目添加到您的 AppTheme

<item name="actionMenuTextColor">@android:color/white</item>

您可以通过android:textColorPrimary自定义Toolbar的标题textColor。

例子

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    ...
    <!-- Used for the title -->
    <item name="android:textColorPrimary">#ffeb3b</item>
    <!-- Used for the menu and back-arrow - can be overriden by colorControlNormal -->
    <item name="android:textColorSecondary">#03a9f4</item>
</style>