如何设置自定义的动作条的颜色/风格?自定义、如何设置、颜色、风格

2023-09-12 01:35:06 作者:淡忘你给的伤i

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

从这里摘自:How修改我在使用XML的ActionBarActivity的动作条的背景颜色?

 
精彩推荐