How to Change Action Bar Title Color in Code

Change Action Bar Title color

From Jake Wharton's ActionBarSherlock site :

Mirrored Attributes

Due to limitations in Android's theming system any theme
customizations must be declared in two attributes. The normal
android-prefixed attributes apply the theme to the native action bar
and the unprefixed attributes are for the custom implementation.

Had to change MyTheme.ActionBarStyle to :

   <style name="MyTheme.ActionBarStyle" parent="@style/Widget.Sherlock.ActionBar">
<item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>

Now the Title text color has changed.

Android - Change Actionbar Title Text Color

wandering around StackOverflow I found this answer which finally worked.

I report it here:

<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/ActionBar</item>
...
</style>

<style name="ActionBar" parent="@android:style/Widget.ActionBar">
<item name="android:titleTextStyle">@style/ActionBar.Title</item>
<item name="android:subtitleTextStyle">@style/ActionBar.Subtitle</item>
...
</style>

<style name="ActionBar.Title">
<item name="android:textColor">@color/my_color</item>
</style>

<style name="ActionBar.Subtitle">
<item name="android:textColor">@color/my_color</item>
</style>

Can't change ActionBar title text color

I am using this and it works for me

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="titleTextColor">@android:color/white</item>
<item name="subtitleTextColor">@android:color/white</item>
</style>

How to change action bar title color in code

The ActionBar title ID is hidden, or in other words, it's internal and accessing it can't be done typically. You can reference it using Resources.getIdentifier then View.findViewById though.

Grab the ID for the action_bar_title

int titleId = getResources().getIdentifier("action_bar_title", "id", "android");

Now you can use the ID with a TextView

TextView abTitle = (TextView) findViewById(titleId);
abTitle.setTextColor(colorId);

Change the title text color in the Android ActionBar via xml

I solved my problem. The problem was that I was testing in a device with api level 14+ and I just added the style to res/values . I had to add the style in res/values-v14 too. I attach my code:

res/values/styles.xml

<resources xmlns:android="http://schemas.android.com/apk/res/android">

<style name="Theme.Dbtools_style" parent="@style/Theme.AppCompat.Light">
<!-- Title Text Color -->
<item name="actionMenuTextColor">@color/white</item>
</style>

<style name="ActionBar.Solid.Dbtools_style" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
<!-- Title Text Color -->
<item name="titleTextStyle">@style/MyActionBarTitleText</item>
</style>

<!-- ActionBar title text -->
<style name="MyActionBarTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/white</item>
</style>

res/values-v14/styles.xml

<style name="Theme.Dbtools_style" parent="@style/Theme.AppCompat.Light">

<item name="android:actionBarStyle">@style/ActionBar.Solid.Dbtools_style</item>

<!-- Title Text Color -->
<item name="android:actionMenuTextColor">@color/white</item>
</style>

<style name="ActionBar.Solid.Dbtools_style" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
<!-- Title Text color -->
<item name="android:titleTextStyle">@style/MyActionBarTitleText</item>
</style>

<!-- ActionBar title text -->
<style name="MyActionBarTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/white</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>

Change actionbar background and title color

Styles : Main App Theme

<style name="MyAppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">

<item name="android:actionBarStyle">@style/CustomActionBarStyle</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/CustomActionBarStyle</item>

</style>

Setup styles for text and background color

<style name="CustomActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">@color/white</item>
<item name="android:titleTextStyle">@style/MyActionBarTitleText</item>

<item name="background">@color/white</item>
<item name="titleTextStyle">@style/MyActionBarTitleText</item>
</style>

Setup TextColor Impt: parent must @style/TextAppearance.AppCompat.Widget.ActionBar.Title

<style name="MyActionBarTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/action_bar_text_color</item>
</style>

For more refer links posted in @Santosh Shinde post

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

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>

Change action bar Title font & color

Change you Theme.AppCompat.Light to Theme.AppCompat.Light.DarkActionBar and tried code as below

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

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

<style name="MyTheme.MyActionBar.TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/colorWhite</item>
<item name="android:textStyle">normal</item>
</style>


Related Topics



Leave a reply



Submit