Android - 更改Actionbar标题文本颜色

18

我正在开发一个应用程序,我想要 更改操作栏标题的文本颜色。现在,在我的清单中定义了一个主题:

<application
        android:theme="@style/AppTheme">
</application>

它在styles.xml中定义:

<style name="AppTheme" parent="android:style/Theme.Holo.Light">
        <item name="android:textViewStyle">@style/AppTheme.TextView</item>
        <item name="android:actionBarStyle">@style/AppTheme.ActionBarStyle</item>
    </style>

    <style name="AppTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:titleTextStyle">@style/AppTheme.ActionBar.TitleTextStyle</item>
    </style>

    <style name="AppTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
        <item name="android:textColor">@color/themeapp</item>
    </style>

    <style name="AppTheme.TextView" parent="@android:style/Widget.TextView">
        <item name="android:textColor">#FFFFFF</item>
    </style>

这个方法不起作用,但我不知道为什么。根据这个答案,这应该可以工作。文本视图样式也无效。

我做错了什么?

更新: 已按照Grace Feng的答案进行更改。


暂时还没有。 - jack_the_beast
13个回答

0
刚刚遇到这个问题,终于找到解决方法了。 在你的style.xml文件中,不要为你的工具栏(toolbar)指定背景颜色。 然后在每个layout.xml文件中定义颜色。
<android.support.v7.widget.Toolbar
    android:id="@+id/my_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="#B678EE"
    android:elevation="4dp"
    android:theme="@style/ToolbarTheme"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

这样可以让您灵活地根据需要在不同的活动中轻松设置不同的操作栏颜色。


0

这是可用的代码。请按照此代码操作。

<style name="AppTheme" parent="Theme.AppCompat.Light">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorApp</item>
</style>

<style name="TextAppearance.AppCompat.Widget.ActionBar.Title" parent="@android:style/TextAppearance">
    <item name="android:textSize">23dp</item>
    <item name="android:textColor">@color/YOUR_COLOR</item>
</style>

在第二个样式标签中,我们可以自定义操作栏标题。
现在将以上代码添加到Manifest文件中的应用程序。
<application
        android:theme="@style/AppTheme">
        <activity>  .....  </activity>
        <activity>  .....  </activity>
</application>

0

Activity的主题更改为:

<style name="ThemeName" parent="android:Theme.Holo.Light">

   <item name="android:actionMenuTextColor">@color/white</item>

</style>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接