如何更改Material Design ActionBar的文本?

14

我正在玩弄一下使用新的 Material Design 制作 Android 应用程序,但我无法弄清如何更改 ActionBar 上文本的颜色。

我有这个:


<style name="AppTheme" parent="@android:style/Theme.Material.Light">
    <item name="android:colorPrimary">#ff3d00</item>
    <item name="android:colorPrimaryDark">#dd2c00</item>
    <item name="android:colorAccent">#ff3d00</item>
</style>

但是它看起来像这样:

enter image description here

我不太喜欢橙色背景上的黑色文字。我试着做了这个:

<style name="AppTheme" parent="@android:style/Theme.Material">
    <item name="android:colorPrimary">#ff3d00</item>
    <item name="android:colorPrimaryDark">#dd2c00</item>
    <item name="android:colorAccent">#ff3d00</item>
</style>

然后它看起来像这样:

在此处输入图像描述

正如您所看到的,ActionBar 文本的颜色确实发生了变化,但背景变成了灰色,这不是我想要的。

我应该怎么做呢?提前感谢!

2个回答

22

我认为在这种情况下,只需将样式更改为 Theme.Material.Light.DarkActionBar 即可。您将获得浅色界面元素,但具有浅色标题文本的“黑暗”操作栏。


谢谢,问题已解决! - jvnknvlgl
只是出于好奇,更改windowBackground颜色也有效吗?请参考此处的标记图:https://developer.android.com/preview/material/theme.html - Tim Trueman
文本颜色可以改成其他颜色吗? - android developer
DarkActionBar给我在API 17上带来了向后兼容性问题。 - Spidfire

-1
在你的 build.gradle 项目依赖中添加 appcompat-v7:21.0.0。
..

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:21.0.0'
    compile 'com.android.support:support-v4:21.0.0'
    .....
}

然后从appcompat继承您的样式

<style name="AppTheme" parent="@style/Theme.AppCompat">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
       ........
</style>

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