如何改变Android的动作条的颜色,而无需使用任何图像资源? [英] How to change the color of the android actionbar without using any image resource?

查看:125
本文介绍了如何改变Android的动作条的颜色,而无需使用任何图像资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变我的动作条的颜色,但我不是善于使图像资源,所以我想知道是否有无论如何它是可以做到的,没有图像。喜欢的颜色设置,有些人的物业什么的?我冲浪了很多,但有太多的混乱答案,我想不出使用哪一个。
我开发SDK上述8所以我使用支持库。请大家帮帮忙。

I want to change the color of my actionbar but I'm no good at making image resources so I want to know if there is anyway it is possible to do that without images. like setting a color to some property or something? I surfed a lot but there are too many confusing answers and I can't figure out which one to use.
I am developing for sdk above 8 so I'm using support libraries. Please help.

推荐答案

您可以很容易地找到了答案的此处。或者你可以点击此处很容易地创建图像资源。但无论如何,这是你如何做到这一点。
首先,在你的项目中像这样的价值的文件夹定义要颜色为colors.xml你的动作条:

You could have easily found out the answer here. Or you can click here to create image resources very easily. But anyway, this is how you do it.
first of all, define a color you want for your actionbar in "colors.xml" in the "values" folder of your project like this:

    <color name="customColor">#f1f1f1</color>

然后创建一个在您绘制文件夹的名称创建新.xml文件说actionbar_drawable.xml。它必须是一个形绘制。

Then create a new .xml file in your drawable folder with the name say "actionbar_drawable.xml". It has to be a "shape" drawable.

绘制\ actionbar_drawable.xml

drawable\actionbar_drawable.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >    
    <solid 
        android:color="@color/customColor"/>    
</shape>

现在创造价值文件夹的themes.xml具有以下code:

Now create "themes.xml" in "values" folder with the following code:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">

    <style name="CustomActionBar" parent="@style/Theme.AppCompat.Light">
       <item name="android:actionBarStyle" tools:targetApi="11">@style/CustomBar</item>
    <!-- Support library compatibility -->
       <item name="actionBarStyle">@style/CustomBar</item>         
    </style>

    <style name="CustomBar"
         parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
       <item name="android:background">@drawable/actionbar_drawable</item>
    <!-- Support library compatibility -->
       <item name="background">@drawable/actionbar_drawable</item>
    </style>
</resources>

然后在你的清单文件,设置主题为您的活动是这样的:

Then in your manifest file, set the theme for your activity like this:

android:theme="@style/CustomActionBar"  

这就是全部。现在,你不必做任何图像资源。希望这对您有所帮助。

That's all. Now you won't have to make any image resource. Hope it's helpful to you.

这篇关于如何改变Android的动作条的颜色,而无需使用任何图像资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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