Reputation: 3419
I am editing the style xml trying to get the Activity title bold.
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#81CFEB</item>
<item name="android:textStyle">bold</item>
</style>
But only what I can set is the background color desired. I do not why the textStyle is not set to bold.
Anyone know how to solve it?
Upvotes: 11
Views: 14373
Reputation: 344
There's an alternative to styling the ActionBar
globally inside the themes file.
As the ActionBar.setTitle()
method accepts a CharSequence
(not just a String
), you can style it with Html.fromHtml()
:
Java:
if (Build.VERSION.SDK_INT >= 24) {
getSupportActionBar().setTitle(Html.fromHtml("<b>" + title + "</b>", 0));
} else {
getSupportActionBar().setTitle(Html.fromHtml("<b>" + title + "</b>"));
}
Kotlin:
if (Build.VERSION.SDK_INT >= 24) {
supportActionBar?.title = Html.fromHtml("<b>$title</b>", 0)
} else {
supportActionBar?.title = Html.fromHtml("<b>$title</b>")
}
This can be useful, if you want to make the ActionBar
title bold in only a single Activity
.
Upvotes: -1
Reputation: 3485
For those using AppCompat, you'll need something like this:
<style name="MyTheme" parent="Theme.AppCompat">
<item name="android:actionBarStyle">@style/MyTheme.ActionBar</item>
<item name="actionBarStyle">@style/MyTheme.ActionBar</item>
</style>
<style name="MyTheme.ActionBar" parent="Widget.AppCompat.ActionBar.Solid">
<item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="TextAppearance.AppCompat">
<item name="android:background">#81CFEB</item>
<item name="android:textStyle">bold</item>
</style>
Upvotes: 4
Reputation: 3177
Can you please try with this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyTheme.MyActionBar</item>
</style>
<style name="MyTheme.MyActionBar"parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/MyTheme.MyActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.MyActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:background">#81CFEB</item>
<item name="android:textStyle">bold</item>
</style>
</resources>
Upvotes: 29