简体   繁体   English

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

[英]How to set the text color of titlebar?

I am using this as the theme. 我用这个作为主题。

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

With this background image is got assigned but text color is not changing. 使用此背景图像已分配,但文本颜色不会更改。

In manifest I am using like this. 在清单中我使用这样的。

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

This is worked for me. 这对我有用。

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

Try this 尝试这个

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

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

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

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

Yas Bro You can do this... Yas Bro你可以做到这一点......

even you made your own custom titlebar ... 即使你自己制作了自定义标题栏......

Just Go through this link 只需浏览此链接

How to change the text on the action bar 如何更改操作栏上的文本

which is from stackoverflow. 来自stackoverflow。

Here's a code snippet I found online: It worked perfectly for me. 这是我在网上找到的代码片段:它对我来说很有效。

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

Call this method just after your setContentView(R.layout.main_activity) line in your main activity. 在主活动中的setContentView(R.layout.main_activity)行之后调用此方法。 If you are using a standard activity replace the instances of getSupportActionBar with getActionBar. 如果您使用的是标准活动,请将getSupportActionBar的实例替换为getActionBar。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM