如何在Android 5.0 Lollipop中更改ActionBar文本颜色?

6

我该如何将Android Lollipop中ActionBar中的文本颜色从黑色改为白色?

这是我的当前样式。

<style name="AppCustomTheme" parent="@style/Theme.AppCompat.Light">
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">@color/orange_bar</item>
</style>
3个回答

7

使用@style/Theme.AppCompat.Light.DarkActionBar来交换文本的着色和许多其他属性,以更好地适应较暗的操作栏。


1
这似乎是一个更好的解决方案,因为例如仅将textColorPrimary设置为白色也会更改下拉菜单上的文本,使其难以阅读。使用DarkActionBar可以使操作栏上的文本变为白色,但保持菜单上的文本为黑色。 - Tony Wickham

5

我阅读了更多资料并发现,为了改变Android Lollipop中ActionBar的默认颜色,您需要添加此标记。

    <!--textColorPrimary is used to change the text color of the default action bar-->
    <item name="android:textColorPrimary">#FFFFFF</item>

2

我已在5.0 Lollipop4.4 KitKat上进行过测试。

<style name="MyAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

    <!-- To change action bar text color -->
    <item name="android:textColorPrimary">#123</item>

    <!-- This has to be here to make it work; let me know if you know why -->
    <item name="actionBarTheme">@style/ThemeOverlay.AppCompat.ActionBar</item>        

</style>

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