android中的进度条进度颜色

时间:2013-08-14 12:21:37

标签: android progress android-theme android-progressbar

我正在创建一个将进度条作为其中一个组件的应用程序。

我想使用设备主题自定义进度条的颜色。我无法通过它。

我的应用程序的最低级别是11。 以下是图片。但我已明确地将颜色提供给进度条。但我希望它根据不同的设备主题,进步的颜色也应该改变。 enter image description here

enter image description here

例如,在附加的图像中,选项卡选择的颜色和进度条的进度是相同的。

2 个答案:

答案 0 :(得分:1)

请使用以下代码......

seekbar_progress.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:id="@android:id/background"
    android:dither="true"
    android:drawable="here set your gray image">// if possible so use 9-patch image
</item>
<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
            <gradient
                android:angle="270"
                android:centerColor="#FFFFFF"
                android:centerY="0.75"
                android:endColor="#FFFFFF"
                android:startColor="#FFFFFF" />
        </shape>
    </clip>
</item>
<item
    android:id="@android:id/progress"
    android:drawable="@drawable/seekbar_progress_bg"/>

</layer-list>

seekbar_progress_bg.xml

    <?xml version="1.0" encoding="utf-8"?>
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <clip>
    <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="Here use your blue image"// if possible so use 9-patch images
        android:tileMode="repeat"
        android:antialias="true"
        android:dither="false"
        android:filter="false"
        android:gravity="left"
    />
    </clip>
</item>
 </layer-list>

请在后台栏中将背景设置为seek_bar.xml。

答案 1 :(得分:0)

您可以使用this网站为您创建自定义主题。只需下载文件夹并将所有文件复制到正确的res文件夹中(不要替换,因为您将丢失所有已经制作的布局和样式以及值),然后设置进度条的样式作为这些文件中相应样式的任何其他元素。我喜欢这种方法而不是手工完成所有事情,因为它可以为简单的任务节省时间和精力,例如更改常规应用主题以及特定元素。

相关问题