【问题标题】:How to set the text color of titlebar?如何设置标题栏的文字颜色?
【发布时间】:2013-08-30 05:44:29
【问题描述】:

我用这个作为主题。

<style name="ThemeSelector" parent="android:Theme.Light">
    <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>
    <item name="android:textAppearance">@style/TitleTextColor</item>
</style>

<style name="WindowTitleBackground">
    <item name="android:background">@drawable/waterblue</item>        
</style>

<style name="TitleTextColor">
    <item name="android:textColor">@color/white</item>
</style>

已分配此背景图像,但文本颜色没有改变。

在清单中我是这样使用的。

<application
    android:name="com.example"
    android:allowBackup="true"
    android:icon="@drawable/logo"
    android:label="@string/app_name"
    android:theme="@style/ThemeSelector">

【问题讨论】:

  • 如何在 TextView 中使用这种样式?
  • 尝试为 textview 应用主题......
  • 有什么方法可以控制 TitleBar TextView 或者你告诉我要创建自定义 TitleBar。

标签: android android-titlebar


【解决方案1】:

这对我有用。

<resources xmlns:android="http://schemas.android.com/apk/res/android">

<style name="ThemeSelector" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/myTheme.ActionBar</item>        
</style>

<style name="myTheme.ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">@drawable/lblue</item>
    <item name="android:titleTextStyle">@style/myTheme.ActionBar.Text</item>
    <item name="android:height">@dimen/app_head_height</item>
</style>

<style name="myTheme.ActionBar.Text" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/white</item>
    <item name="android:textSize">@dimen/app_head</item>
</style>

【讨论】:

    【解决方案2】:

    试试这个

    <style name="ThemeSelector" parent="android:Theme.Light">
        <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>
        <item name="android:titleTextStyle">@style/TitleTextColor</item>
    </style>
    
    <style name="WindowTitleBackground">
        <item name="android:background">@drawable/waterblue</item>        
    </style>
    
    <style name="TitleTextColor">
        <item name="android:text">@string/app_name</item>
            <item name="android:textSize">10sp</item>
            <item name="android:textColor">#a23421</item>
    </style>
    

    【讨论】:

    • 我试过了,它设置的是“WindowTitleBackground”而不是“TitleTextColor”
    【解决方案3】:

    在您的style.xml 中为 API 级别 23 及更高级别添加以下行。

    <item name="android:titleTextColor">@color/black</item>
    

    【讨论】:

      【解决方案4】:

      我猜属性名称将是 android:titleTextStyle 而不是 android:textAppearance

      【讨论】:

        【解决方案5】:

        是的,兄弟,你可以这样做......

        即使您制作了自己的自定义标题栏...

        只需通过此链接

        How to change the text on the action bar

        来自stackoverflow。

        【讨论】:

          【解决方案6】:

          这是我在网上找到的代码 sn-p: 它对我来说非常有效。

          private void createCustomActionBar() {
              this.getSupportActionBar().setDisplayShowCustomEnabled(true);
              this.getSupportActionBar().setDisplayShowTitleEnabled(false);
              LayoutInflater inflator = LayoutInflater.from(this);
              View v = inflator.inflate(R.layout.title_bar, null);
              Typeface tf = Typeface.createFromAsset(getAssets(),"Lobster-Regular.ttf");
              ((TextView)v.findViewById(R.id.lblActionBarTitle)).setTypeface(tf);
              ((TextView)v.findViewById(R.id.lblActionBarTitle)).setTypeface(tf);
              this.getSupportActionBar().setCustomView(v);
              this.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#212121")));
          }
          

          在您的主要活动中的 setContentView(R.layout.main_activity) 行之后调用此方法。如果您使用的是标准活动,请将 getSupportActionBar 的实例替换为 getActionBar。

          【讨论】:

            猜你喜欢
            • 2020-09-30
            • 2015-09-14
            • 2015-01-07
            • 1970-01-01
            • 1970-01-01
            • 2018-02-23
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多