【问题标题】:How To Change Action Bar Text Color如何更改操作栏文本颜色
【发布时间】:2014-03-29 05:33:40
【问题描述】:

如何将我的操作栏文本颜色从白色更改为黑色?我不想使用操作栏 Sherlock .

这是我的操作栏代码。

ActionBar ab = getActionBar(); 
    ab.setDisplayUseLogoEnabled(false);
    ab.setDisplayShowHomeEnabled(true);
    ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
    ab.setCustomView(R.layout.actionbar);
    ab.setDisplayHomeAsUpEnabled(true);
    ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#33CCFF"));     
    ab.setBackgroundDrawable(colorDrawable);

这是操作栏的自定义视图:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:orientation="vertical">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="@string/title"
    android:textColor="#ffffff"
    android:textSize="24sp" />
</LinearLayout>

这里 style.xml :

    <resources>
    <style name="AppBaseTheme"  parent="@android:style/Theme.Holo.Light">
    </style>
    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
    </style>
</resources>

我可以知道实现目标的正确方法是什么吗?也许这个问题太基础了,但我没有找到任何合适的解决方案。请帮帮我。

【问题讨论】:

标签: android xml android-actionbar


【解决方案1】:

试试这种风格:

您可以在样式中编辑 TitleTextStyle:

<?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/black</item>
  </style>
</resources>

【讨论】:

    【解决方案2】:

    这里是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>
    

    感谢rnoway

    【讨论】:

      【解决方案3】:
        <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:orientation="vertical">
      
      <TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:text="@string/title"
          android:textColor="#ffffff"      //  change the color code your wat , instead of #ffffff put youra
          android:textSize="24sp" />
      

      你可以从

      找到颜色代码

      http://www.w3schools.com/tags/ref_colorpicker.asp

      【讨论】:

        【解决方案4】:

        只需使用html设置标题,并指定文本颜色。例如,要将 ActionBar 文本颜色设置为红色,只需执行以下操作:

        getActionBar()/* or getSupportActionBar() */.setTitle(Html.fromHtml("<font color=\"#000000\">" + getString(R.string.app_name) + "</font>"));
        

        【讨论】:

          猜你喜欢
          • 2012-07-31
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-12-13
          • 2023-03-09
          • 2014-12-24
          相关资源
          最近更新 更多