如何设置自定义ActionBar颜色/样式? [英] How to set custom ActionBar color / style?
问题描述
我在我的项目中使用 Android导航栏
我想将操作栏中的顶部颜色更改为红色,我该如何做?
我有这样的东西,
I am using Android Navigation bar
in my project,
I want to change the top color in action bar to something red, How can i do that?
I have something like this,
,我想要这样的东西,
如何实现?
推荐答案
您可以通过创建自定义样式来定义ActionBar(和其他材料)的颜色:
You can define the color of the ActionBar (and other stuff) by creating a custom Style:
只需编辑Android项目的 res / values / styles.xml 文件。
Simply edit the res/values/styles.xml file of your Android project.
例如: p>
For example like this:
<resources>
<style name="MyCustomTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBarTheme</item>
</style>
<style name="MyActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
</resources>
然后将MyCustomTheme设置为包含ActionBar的Activity的主题。 strong>
Then set "MyCustomTheme" as the Theme of your Activity that contains the ActionBar.
您还可以为ActionBar设置一个颜色,如下所示:
You can also set a color for the ActionBar like this:
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.RED)); // set your desired color
从这里获取:如何使用XML更改ActionBarActivity的ActionBar的背景颜色?
这篇关于如何设置自定义ActionBar颜色/样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!