简体   繁体   English

我的动作栏标题的主题颜色错误

[英]My action bar title is taking the wrong color from theme

I'm attempting to modify the theme for my application. 我正在尝试为我的应用程序修改主题。 I've been able to successfully set the background color for my app, and the background color for my action bar. 我已经能够成功设置应用程序的背景色和操作栏的背景色。

Unfortunately, the background color of the items WITHIN the action bar are taking the background color of the app, not the bg color of the action bar. 不幸的是,操作栏内的项目的背景颜色采用的是应用程序的背景色,而不是操作栏的bg颜色。

Here's my code from styles.xml 这是我来自styles.xml的代码

<!--
    Base application theme for API 11+. This theme completely replaces
    AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
</style>


<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:background">#ff0000</item>
</style>


<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">#fefefe</item>
</style>

and here's a screenshot of what's happening. 这是正在发生的事情的屏幕截图。

怪异的bg颜色的屏幕截图

Hoping I'm missing something stupid here... 希望我在这里想念一些愚蠢的东西...

Thanks! 谢谢!

I'm pretty sure your theme background is being applied to everything . 我确信您的主题背景已经应用于一切 Instead, you only want the activity's background to be that color. 相反,您只希望活动的背景是该颜色。 So instead of setting the background color in the theme, you should set it for the activity. 因此,应在活动中设置背景色,而不是在主题中设置背景色。 If you have many activities that will use this background color, then create a style for your activities and apply it to each one. 如果您有许多活动将使用此背景色,请为您的活动创建一种样式并将其应用于每个样式。

Try using: 尝试使用:

<item name="android:windowBackground">@color/your_color</item>
<item name="android:colorBackground">@color/your_color</item>

Worked for me. 为我工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM