How to set bold title in Action Bar?

2019-02-16 13:59发布

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?

3条回答
戒情不戒烟
2楼-- · 2019-02-16 14:36

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>
查看更多
啃猪蹄的小仙女
3楼-- · 2019-02-16 14:37

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>
查看更多
祖国的老花朵
4楼-- · 2019-02-16 14:44

if (Build.VERSION.SDK_INT >= 24) {getSupportActionBar().setTitle(Html.fromHtml("" + title + "", 0));} else {getSupportActionBar().setTitle(Html.fromHtml("" + title + ""));}

查看更多
登录 后发表回答