Change ActionBar title text color using Light.DarkActionBar theme in AppCompat 21

我的未来我决定 提交于 2019-11-27 17:35:18

You can change it with actionBarStyle attribute of theme.

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

<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar.Solid">
    <item name="titleTextStyle">@style/MyTitleTextStyle</item>
</style>

<style name="MyTitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">CHANGE_COLOR_HERE</item>
</style>

This will make your Toolbar Title use white color:

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

To understand what is the difference between ThemeOverlay.AppCompat.Dark.ActionBar and Theme.AppCompat.Light.DarkActionBar check this answer

It's app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" that applies a light colour because the title colour which is used in this theme is white.

make sure you make the changes in all your values folder, like 'values-v11', 'values-v14' etc.. if it exists.

Else make sure the same 'AppTheme' you shown above is being used in the app.

Please post you full style.xml and the manifest code referring the style which will give more insights on your problem.

Also you can try setting app:theme and app:popupTheme attributes on you ToolBar.

Try adding this in the onCreate of your Activity . Works on almost every Android version.

For java Activity:

 actionBar.setTitle(Html.fromHtml("<font color='#ffff00'>Your Title</font>"));  

For fragments:

getSupportActionBar().setTitle(Html.fromHtml("<font color='#ffff00'>Your Title</font>"));

I used a generated layout xml file and didn't notice that the android:theme attribute was overriden.

Did you check yours? :)

Try this:

<item name="actionMenuTextColor">@color/red</item>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!