Change Action Bar Title color

2019-01-13 13:13发布

My code is as below and while it works ( when I change the parent Theme to Theme.Sherlock or Theme.Sherlock.Light the Theme it does changes) it does not changes the Title color.

The code is pretty much the same as here

Code :

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="MyTheme" parent="@style/Theme.Sherlock">
 <item name="actionBarStyle">@style/MyTheme.ActionBarStyle</item>
 <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>

<style name="MyTheme.ActionBarStyle" parent="@style/Widget.Sherlock.ActionBar">
     <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>

<style name="MyTheme.ActionBar.TitleTextStyle" parent="@style/TextAppearance.Sherlock.Widget.ActionBar.Title" >
     <item name="android:textColor">#FF0000</item>
</style>

</resources>

7条回答
闹够了就滚
2楼-- · 2019-01-13 13:40

i have changed title color like this

actionBar.setTitle(Html.fromHtml("<font color='#ff0000'>ActionBarTitle </font>"));
查看更多
相关推荐>>
3楼-- · 2019-01-13 13:40

From Jake Wharton's ActionBarSherlock site :

Mirrored Attributes

Due to limitations in Android's theming system any theme customizations must be declared in two attributes. The normal android-prefixed attributes apply the theme to the native action bar and the unprefixed attributes are for the custom implementation.

Had to change MyTheme.ActionBarStyle to :

   <style name="MyTheme.ActionBarStyle" parent="@style/Widget.Sherlock.ActionBar">
     <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
     <item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
   </style>

Now the Title text color has changed.

查看更多
祖国的老花朵
4楼-- · 2019-01-13 13:51

in your style.xml in values folder this will change your action bar color.. Replace #666666 with your selected color code for title background color and replace #000000 for your title text color.

<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/NewActionBar</item>
</style>

<style name="NewActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/TitleBarTextColor</item>
<item name="android:background">#666666</item>
</style>
<style name="TitleBarTextColor" parent="@style/TextAppearance.Sherlock.Widget.ActionBar.Menu">
    <item name="android:textColor">#000000</item>
</style>

then dont forget to edit your manifest file -> android:theme="@style/NewTheme"

    <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/NewTheme" >
    <activity
        android:name="com.nearby.welcome.Splash"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>
查看更多
何必那么认真
5楼-- · 2019-01-13 13:57

Simplest way that worked for me is to add the following in theme style:

<item name="android:textColorPrimary">@color/orange_dark</item>
查看更多
再贱就再见
6楼-- · 2019-01-13 14:02

If you are trying to change the title text where you have a custom toolbar then try adding app:titleTextColor to the toolbar as below:

 <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:titleTextColor="@color/colorWhite" />
查看更多
我想做一个坏孩纸
7楼-- · 2019-01-13 14:03

Use below code to provide different color to actionbar text and actionbar background just use below theme in manifest against the activity in which you want output :)

 <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:titleTextStyle">@style/TitleBarTextColor</item>
        <item name="android:background">YOUR_COLOR_CODE</item>
    </style>

    <style name="TitleBarTextColor" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">YOUR_COLOR_CODE</item>
    </style>
查看更多
登录 后发表回答