40

我的代码如下,当它工作时(当我将父主题更改为 Theme.Sherlock 或 Theme.Sherlock.Light 时,它确实改变了主题)它不会改变标题颜色。

代码和这里差不多

代码 :

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

8 回答 8

63

我已经像这样更改了标题颜色

actionBar.setTitle(Html.fromHtml("<font color='#ff0000'>ActionBarTitle </font>"));
于 2014-06-21T11:01:17.417 回答
40

来自 Jake Wharton 的 ActionBarSherlock 网站:

镜像属性

由于 Android 主题系统的限制,任何主题自定义都必须在两个属性中声明。普通的 android-prefixed 属性将主题应用于本机操作栏,unprefixed 属性用于自定义实现。

必须将MyTheme.ActionBarStyle更改为:

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

现在标题文本颜色已更改。

于 2013-05-05T14:06:29.023 回答
15

使用下面的代码为操作栏文本和操作栏背景提供不同的颜色,只需在清单中针对您想要输出的活动使用下面的主题:)

 <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>
于 2014-08-21T08:43:40.283 回答
9

对我有用的最简单的方法是在主题样式中添加以下内容:

<item name="android:textColorPrimary">@color/orange_dark</item>
于 2016-08-30T19:58:12.530 回答
8

我尝试了所有上述方法,它对我不起作用。我刚刚通过下面的代码实现了..

Spannable text = new SpannableString(actionBar.getTitle());
text.setSpan(new ForegroundColorSpan(Color.BLUE), 0, text.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
actionBar.setTitle(text);
于 2015-11-12T13:09:55.963 回答
7

如果您尝试更改具有自定义工具栏的标题文本,请尝试添加app:titleTextColor到工具栏,如下所示:

 <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" />
于 2018-05-23T05:28:02.613 回答
2

在 values 文件夹中的 style.xml 中,这将更改您的操作栏颜色。将 #666666 替换为您选择的标题背景颜色颜色代码,并将 #000000 替换为标题文本颜色。

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

然后别忘了编辑你的清单文件 -> 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>
于 2014-11-03T07:28:49.940 回答
-1

如果您想更改 ActionBar 标题颜色,请先按照此操作。转到 style.xml 并在资源中使用以下代码

<style name="ActionBar.Solid.Ribbit.TitleTextStyle"
    parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">@color/actionBarTextColor</item>
</style>
于 2020-01-10T14:36:22.520 回答