Reputation: 105
Can I know how to change the color of the title in ActionBar to black color based on the xml code below? I have tried several methods found but it doesn't really work.
Below are the part of the style xml code:::
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="TestingBaseTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/ActionBarTheme</item>
<item name="android:actionBarTabTextStyle">@style/ActionBarTabText</item>
<item name="android:actionMenuTextColor">@color/white</item>
<item name="android:textColor">@color/black</item>
</style>
<style name="ActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/white</item>
</style>
<style name="ActionBarTabText" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/white</item>
</style>
<style name="ActionBarTitleText" parent="@android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/yellow</item>
</style>
Upvotes: 0
Views: 325
Reputation: 1145
You may use this code snippet:
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
SpannableString spannableString = new SpannableString(getSupportActionBar().getTitle()+"");
spannableString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(MainActivity.this, R.color.yellow)), 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableStringBuilder.append(spannableString);
getSupportActionBar().setTitle(spannableStringBuilder);
Upvotes: 0
Reputation: 10076
i found simplest and most easy code
actionBar.setTitle(Html.fromHtml("<font color='#ff0000'>ActionBarTitle </font>"));
Upvotes: 1
Reputation: 155
Here is the answer : click below link
Ok I've found a better way. I'm now able to only change the color of the title, you can also tweak the subtitle.
Here is my styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle"parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/red</item>
</style>
</resources>
Upvotes: 1
Reputation: 347
in your activity set android label in activity android:label= "name"
Upvotes: 0
Reputation: 157437
If I recall correctly the attribute to set ActionBar's text style is
<item name="android:titleTextStyle" tools:ignore="NewApi"
I also noticed that you are using ActionBarCompat. If you are targeting pre HoneyComb devices you have also to add the same attribute without the android:
prefix
<item name="titleTextStyle" tools:ignore="NewApi"
Upvotes: 0