基本上我遵循了关于自定义操作栏的指南https://developer.android.com/training/basics/actionbar/styling.html
并在我的styles.xml 中使用此样式
<style name="Blue" parent="Theme.AppCompat">
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">@color/light_blue</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">@color/dark_blue</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">@color/light_blue</item>
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">@style/MyActionBarTabText</item>
<item name="android:actionMenuTextColor">@color/white</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
<item name="actionBarTabTextStyle">@style/MyActionBarTabText</item>
<item name="actionMenuTextColor">@color/white</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>
<item name="android:subtitleTextStyle">@style/MyActionBarSubtitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText"
parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/white</item>
<!-- The textColor property is backward compatible with the Support Library -->
<item name="textColor">@color/white</item>
</style>
<!-- ActionBar subtitle text -->
<style name="MyActionBarSubtitleText"
parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/white</item>
<item name="android:textSize">10sp</item>
<!-- The textColor property is backward compatible with the Support Library -->
<item name="textColor">@color/white</item>
<item name="textSize">10sp</item>
</style>
<!-- ActionBar tabs text -->
<style name="MyActionBarTabText"
parent="@style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">@color/white</item>
<item name="textColor">@color/white</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
但是显然文本和图标的颜色保持为黑色。我是不是错过了什么?
如果您只希望文本为白色,这是Theme.AppCompat
的默认值,或者,如果您想要轻活动,请使用Theme.AppCompat.Light.DarkActionBar