Android的变化卧式进度条的颜色卧式、进度条、颜色、Android

2023-09-11 12:51:37 作者:喋喋咩

我已经设置水平进度条。

I have set Horizontal Progress bar.

我想改变的黄色进步颜色。

I would like to change progress color of yellow.

<ProgressBar android:id="@+id/progressbar" android:layout_width="80dip" 
android:layout_height="20dip" android:focusable="false" 
style="?android:attr/progressBarStyleHorizontal" />

的问题是,进度颜色是在不同的设备不同。 所以,我希望它修复进度的颜色。

The problem is, the progress color is different in different devices. So, I want it to fix the progress color.

推荐答案

我复制这个从我的应用程序之一,所以有概率一些额外的属性,但是应该给你的想法。这是有进度条的布局:

I copied this from one of my apps, so there's prob a few extra attributes, but should give you the idea. This is from the layout that has the progress bar:

<ProgressBar
    android:id="@+id/ProgressBar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:indeterminate="false"
    android:maxHeight="10dip"
    android:minHeight="10dip"
    android:progress="50"
    android:progressDrawable="@drawable/greenprogress" />

然后创建一个新的绘制类似下面的内容(在这种情况下greenprogress.xml):

Then create a new drawable with something similar to the following (In this case greenprogress.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">
    <shape>
        <corners android:radius="5dip" />
        <gradient
                android:startColor="#ff9d9e9d"
                android:centerColor="#ff5a5d5a"
                android:centerY="0.75"
                android:endColor="#ff747674"
                android:angle="270"
        />
    </shape>
</item>

<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
            <corners android:radius="5dip" />
            <gradient
                    android:startColor="#80ffd300"
                    android:centerColor="#80ffb600"
                    android:centerY="0.75"
                    android:endColor="#a0ffcb00"
                    android:angle="270"
            />
        </shape>
    </clip>
</item>
<item
    android:id="@android:id/progress"
>
    <clip>
        <shape>
            <corners
                android:radius="5dip" />
            <gradient
                android:startColor="#33FF33"
                android:endColor="#008000"
                android:angle="270" />
        </shape>
    </clip>
</item>

</layer-list>

您可以更改了颜色需要的,这会给你一个绿色的进度条。

You can change up the colors as needed, this will give you a green progress bar.