Java Android:如何更改操作栏背景颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20440121/
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
Android: how to change action bar background color?
提问by Jennifer
The color of my android application is black. I wish to change it to other color. What is the easiest way to do it? I have tried to make a theme from this link
我的 android 应用程序的颜色是黑色。我想把它改成其他颜色。最简单的方法是什么?我试图从这个链接做一个主题
When the application is opened, I could see that the action bar has changed the color from black to other color but in about 3 seconds, there is a message: Unfortunately, .... has stopped. I wish to use an easier way to may it. Any help is greatly appreciated.
当应用程序打开时,我可以看到操作栏的颜色已从黑色变为其他颜色,但在大约 3 秒后,出现一条消息:不幸的是,.... 已停止。我希望使用更简单的方法来实现它。任何帮助是极大的赞赏。
采纳答案by dr01d3k4
To apply the theme to all activities, change the style.xml like this:
要将主题应用于所有活动,请像这样更改 style.xml:
<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">@style/ActionBarTheme</item>
</style>
<style name="ActionBarTheme" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/action_bar</item>
</style>
And in colours.xml, use:
在 colours.xml 中,使用:
<color name="action_bar">#BA0000</color>
And in the manifest:
在清单中:
<application
android:theme="@style/AppTheme" >