使用Light.DarkActionBar主题AppCompat 21动作条更改标题文本颜色文本、颜色、动作、标题

2023-09-12 02:04:49 作者:妞丶给爷站住

我使用的是V7 appcompat 21库使用的pre-棒棒糖设备,新材料的风格。我styles.xml看起来是这样的:

I'm using the v7 appcompat 21 library to use the new Material styles on pre-Lollipop devices. My styles.xml looks like this:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:textColorPrimary">#ff0000</item>
    <item name="android:textColorPrimaryInverse">#ff0000</item>
</style>

我试图更改操作栏上的文本颜色。但无论怎样,我把对textColorPrimary或​​textColorPrimaryInverse,颜色始终为白色。如果我从Theme.AppCompat继承,我可以覆盖textColorPrimary,如果我从Theme.AppCompat.Light继承,我可以覆盖textColorPrimaryInverse。但无论是工作中使用的Light.DarkActionBar主题的时候。

I am trying to change the text color on the action bar. But no matter what I put for textColorPrimary or textColorPrimaryInverse, the color is always white. If I inherit from Theme.AppCompat, I can override "textColorPrimary", and if I inherit from Theme.AppCompat.Light, I can override "textColorPrimaryInverse". But neither work when using the Light.DarkActionBar theme.

我肯定用AppTheme因为像colorPrimary设置属性来改变动作条的背景颜色正常工作。我没有使用任何其他资源预选赛样式文件。

I am definitely using the AppTheme because setting attributes like colorPrimary to change the actionbar background color works fine. I am not using any other resource qualifier style files.

我已经通过Android风格文件挖似乎无法找出什么属性来覆盖。有任何想法吗?这是一个appcompat错误?

I've dug through the android styles files and can't seem to figure out what attribute to override. Any ideas? Is this an appcompat bug?

推荐答案

您可以用主题 actionBarStyle 属性进行更改。

You can change it with actionBarStyle attribute of theme.

<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar.Solid">
    <item name="titleTextStyle">@style/MyTitleTextStyle</item>
</style>

<style name="MyTitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">CHANGE_COLOR_HERE</item>
</style>