如何设置自定义 ActionBar 颜色/样式? [英] How to set custom ActionBar color / style?
本文介绍了如何设置自定义 ActionBar 颜色/样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的项目中使用 Android Navigation bar
,我想将操作栏中的顶部颜色更改为红色,我该怎么做?我有这样的东西,
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,
我想要这样的东西,
我怎样才能做到这一点?
how can i achieve that?
推荐答案
您可以通过创建自定义样式来定义 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.
例如像这样:
<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 的主题.
您还可以像这样为 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屋!
查看全文