无法更改工具栏文本和图标颜色
Cannot alter Toolbar Text and Icon Colors
我整天都在为这个问题苦苦挣扎 - 我已经在 Stack Overflow 上花了好几个小时尝试各种解决方案,但都无济于事。
我正在构建的应用程序使用浅色 material 主题,但工具栏上的文本拒绝从任何颜色更改为黑色。工具栏本身颜色完美。
styles.xml:
<resources>
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:colorPrimary">@color/primary</item>
<item name="android:colorPrimaryDark">@color/primary_dark</item>
<item name="android:colorAccent">@color/accent</item>
</style>
<style name="Toolbar" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:background">@color/primary</item>
<item name="android:textColor">@color/white</item>
<item name="android:titleTextColor">@color/white</item>
<item name="android:textColorPrimary">@color/white</item>
<item name="android:color">@color/white</item>
<item name="android:elevation">@dimen/toolbar_elevation</item>
</style>
</resources>
在 activity 布局文件中:
<android.support.v7.widget.Toolbar
android:id="@+id/main_toolbar"
style="@style/Toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:title="@string/app_name" />
希望有人能帮助解决这个问题。
将此添加到您的 Toolbar
:
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
或者,添加这个:
ThemeOverlay.AppCompat.Dark.ActionBar
而不是 ThemeOverlay.AppCompat.Dark
我猜你忘了在最后添加 ActionBar
。
当然,如果您有 AppBarLayout
,请尝试在您的 AppBarLayout
中添加此行:
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
文本将为白色。
否则,This answer会有帮助:
Option 1) The quick and easy way (Toolbar only)
Since appcompat-v7-r23
you can use the following attributes directly
on your Toolbar
or its style:
app:titleTextColor="@color/primary_text"
app:subtitleTextColor="@color/secondary_text"
我整天都在为这个问题苦苦挣扎 - 我已经在 Stack Overflow 上花了好几个小时尝试各种解决方案,但都无济于事。
我正在构建的应用程序使用浅色 material 主题,但工具栏上的文本拒绝从任何颜色更改为黑色。工具栏本身颜色完美。
styles.xml:
<resources>
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:colorPrimary">@color/primary</item>
<item name="android:colorPrimaryDark">@color/primary_dark</item>
<item name="android:colorAccent">@color/accent</item>
</style>
<style name="Toolbar" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:background">@color/primary</item>
<item name="android:textColor">@color/white</item>
<item name="android:titleTextColor">@color/white</item>
<item name="android:textColorPrimary">@color/white</item>
<item name="android:color">@color/white</item>
<item name="android:elevation">@dimen/toolbar_elevation</item>
</style>
</resources>
在 activity 布局文件中:
<android.support.v7.widget.Toolbar
android:id="@+id/main_toolbar"
style="@style/Toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:title="@string/app_name" />
希望有人能帮助解决这个问题。
将此添加到您的 Toolbar
:
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
或者,添加这个:
ThemeOverlay.AppCompat.Dark.ActionBar
而不是 ThemeOverlay.AppCompat.Dark
我猜你忘了在最后添加 ActionBar
。
当然,如果您有 AppBarLayout
,请尝试在您的 AppBarLayout
中添加此行:
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
文本将为白色。
否则,This answer会有帮助:
Option 1) The quick and easy way (Toolbar only)
Since
appcompat-v7-r23
you can use the following attributes directly on yourToolbar
or its style:
app:titleTextColor="@color/primary_text"
app:subtitleTextColor="@color/secondary_text"