My action bar title is taking the wrong color from theme

不打扰是莪最后的温柔 提交于 2019-12-11 11:44:40

问题


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.

Here's my code from 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.


Hoping I'm missing something stupid here...

Thanks!


回答1:


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.




回答2:


Try using:

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

Worked for me.



来源:https://stackoverflow.com/questions/16039071/my-action-bar-title-is-taking-the-wrong-color-from-theme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!