如何设置标题栏的文本颜色?

3

我正在使用这个主题。

<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中使用这种样式? - Hardik Joshi
尝试为TextView应用主题... - Piyush
有没有办法获取TitleBar TextView的控制权,或者你是告诉我要创建自定义TitleBar。 - Giri
6个回答

6

这对我有用。

<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

对于API 23及以上的版本,在您的style.xml中添加以下行。

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

1

试试这个

<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"。 - Giri

0

这是我在网上找到的一段代码片段: 它对我来说完美地工作了。

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。

0

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


0

兄弟,你可以做到这一点...

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

只需查看此链接

如何更改操作栏上的文本

该链接来自stackoverflow。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接