[英]Set Background color of Action Bar in Android
Hello I am noob in Android. 您好,我是Android的菜鸟。
I am using appcompat support library to make my application backward compatible. 我正在使用appcompat支持库来使我的应用程序向后兼容。 Here action bar color is
Light
by default I want to change the background color to my custom color. 在这里,操作栏颜色默认为
Light
,我想将背景色更改为自定义颜色。
Any idea how to do this ?? 任何想法如何做到这一点?
styles.xml styles.xml
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
This solved my problem. 这解决了我的问题。 Thanks @Zohra
谢谢@Zohra
ActionBar mActionBar = getActionBar();
mActionBar.setBackgroundDrawable(new ColorDrawable("COLOR"));
You can try to use an approach from official documentation . 您可以尝试使用官方文档中的方法。 I think it has clear example how to do it.
我认为这有一个明确的例子。
your style might look like this 你的风格可能看起来像这样
reference:- https://developer.android.com/training/basics/actionbar/styling.html 参考: -https : //developer.android.com/training/basics/actionbar/styling.html
<style name="CustomActionBarTheme"
parent="@style/Theme.AppCompat.Light">
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<!-- Support library compatibility -->
<item name="background">@drawable/actionbar_background</item>
</style>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.