java 更改android的顶部栏背景颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17148401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 01:09:04  来源:igfitidea点击:

change android's top bar background color

javaandroidlayoutandroid-styles

提问by Arif YILMAZ

I am trying to change the background of the top bar which is created by eclipse automatically. I have read some tutorials and they suggested me to change "styles.xml" file. here is what I have done so far...

我正在尝试更改由 eclipse 自动创建的顶部栏的背景。我已经阅读了一些教程,他们建议我更改“styles.xml”文件。这是我到目前为止所做的......

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:textColor">#008</item>
    <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>
</style>

<style name="WindowTitleBackground">     
    <item name="android:background">#0000FF</item>
</style>

but this doesnt work. would you please take a look at it and tell me what is wrong with this code? because it doesnt do any effects.

但这不起作用。你能看看它并告诉我这段代码有什么问题吗?因为它没有任何效果。

回答by jimmithy

Make sure you reference this theme in your manifest

确保在清单中引用此主题

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

Then make sure your style is created correctly, previously you referenced a theme parent that wasn't in your code sample.

然后确保您的样式创建正确,之前您引用了不在代码示例中的父主题。

<style name="AppTheme" parent="@android:style/Theme.DeviceDefault">
    <item name="android:textColor">#008</item>
    <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>
</style>

<style name="WindowTitleBackground">     
    <item name="android:background">#0000FF</item>    
</style>