如何设置自定义的动作条的颜色/风格? [英] How to set custom ActionBar color / style?

查看:159
本文介绍了如何设置自定义的动作条的颜色/风格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用 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,

和我想是这样的,

我怎样才能做到这一点?

how can i achieve that?

推荐答案

您可以通过定义动作条(和其他的东西)的颜色的创建自定义样式

You can define the color of the ActionBar (and other stuff) by creating a custom Style:

只需编辑 RES /价值/ styles.xml 您的Andr​​oid项目的文件。

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作为活动包含动作条的主题。

您还可以设置颜色的动作条是这样的:

You can also set a color for the ActionBar like this:

ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.RED)); // set your desired color

从这里摘自:<一href="http://stackoverflow.com/questions/8024706/how-do-i-change-the-background-color-of-the-actionbar-of-an-actionbaractivity-us">How修改我在使用XML的ActionBarActivity的动作条的背景颜色?

这篇关于如何设置自定义的动作条的颜色/风格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆