Android更改操作栏文本颜色

时间:2015-05-14 18:48:50

标签: android android-actionbar android-custom-view

我想更改操作栏的颜色而不是我想要的白色文字#59380d,所以我将颜色添加到这样的color.xml中:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#59380d"/>
</selector>

然后我将它调用到我的styles.xml中:

<resources>
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <item name="android:textColor">@color/header</item>
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:textColor">@color/header</item>
    </style>
</resources>

最后在我的AndroidManifest上,我设置了这样的应用程序:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:name="com.app.activities.MyAp"
    android:theme="@style/AppTheme" >

 ...
</aplication>

但是行动栏的文字仍然是白色。我做错了什么

2 个答案:

答案 0 :(得分:1)

对于Android 3.0及更高版本,您需要覆盖:

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

<!-- ActionBar styles -->
<style name="MyActionBar" parent="@style/Widget.Holo.ActionBar">
    <item name="android:titleTextStyle">@style/MyActionBarTitleText</item>
</style>

<!-- ActionBar title text -->
<style name="MyActionBarTitleText" parent="@style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@color/actionbar_text</item>
</style>

对于2.1及更高版本:

<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat">
    <item name="android:actionBarStyle">@style/MyActionBar</item>

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<!-- ActionBar styles -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
    <item name="android:titleTextStyle">@style/MyActionBarTitleText</item>

    <!-- Support library compatibility -->
    <item name="titleTextStyle">@style/MyActionBarTitleText</item>
</style>

<!-- ActionBar title text -->
<style name="MyActionBarTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">@color/actionbar_text</item>
    <!-- The textColor property is backward compatible with the Support Library -->
</style>

答案 1 :(得分:0)

CHange Text COlor

ActionBar actionBar = getActionBar();
         actionBar.setTitle(Html
         .fromHtml("<font color='#59380d'> Your Text </font>"));