【问题标题】:Change color of the title in ActionBar更改 ActionBar 中标题的颜色
【发布时间】:2014-06-16 07:17:27
【问题描述】:

我可以知道如何根据下面的xml代码将ActionBar中的标题颜色更改为黑色吗?我已经尝试了几种方法,但它并没有真正奏效。

下面是部分样式xml代码:::

<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>

【问题讨论】:

    标签: android xml android-layout android-actionbar


    【解决方案1】:

    我找到了最简单最简单的代码

    actionBar.setTitle(Html.fromHtml("<font color='#ff0000'>ActionBarTitle </font>"));
    

    【讨论】:

      【解决方案2】:

      这是答案:点击下面的链接

      ActionBar text color

      好的,我找到了更好的方法。我现在只能改变标题的颜色,你也可以调整字幕。

      这是我的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>
      

      【讨论】:

      • 我们还可以更改活动标签中的操作栏标题,这是首选
      【解决方案3】:

      如果我没记错的话,设置 ActionBar 文本样式的属性是

       <item name="android:titleTextStyle" tools:ignore="NewApi"
      

      我还注意到您正在使用 ActionBarCompat。如果您的目标是预 HoneyComb 设备,您还必须添加相同的属性,但不带 android: 前缀

       <item name="titleTextStyle" tools:ignore="NewApi"
      

      【讨论】:

        【解决方案4】:

        在你的活动中设置 android 标签在活动中 android:label="名称"

        【讨论】:

          【解决方案5】:

          你可以使用这个代码sn-p:

          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);
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2014-07-22
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多