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

时间:2013-08-30 05:44:30

标签: android android-titlebar

我以此为主题。

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

6 个答案:

答案 0 :(得分: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>

答案 1 :(得分: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>

答案 2 :(得分:0)

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

答案 3 :(得分:0)

Yas Bro你可以这样做......

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

只需浏览此链接

How to change the text on the action bar

来自stackoverflow。

答案 4 :(得分:0)

style.xml中为API级别23及更高版本添加以下行。

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

答案 5 :(得分: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。