在 android 中设置剩余进度条颜色

Set remaining progress bar color in android

我正在使用以下样式代码设置进度条的颜色

<item android:id="@android:id/progress">
    <clip>
      <shape>
        <corners android:radius="0dip" />
          <gradient
            android:angle="0"
            android:endColor="#36A19C"
            android:startColor="#36A19C" />
      </shape>
    </clip>
  </item>

我的进度条如下图所示


如何设置进度条中灰色部分的颜色???

尝试查看一些教程here and here

在您的可绘制对象中创建一个文件custom_progressbar.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<!-- Define the background properties like color etc -->
    <item android:id="@android:id/background">
        <shape>
            <gradient
                    android:startColor="backgroundColor"
                    android:endColor="backgroundColor"
                    android:angle="0"
            />
        </shape>
    </item>

 <!-- Define the progress properties like start color, end color etc -->
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <gradient
                    android:startColor="progressColor"
                    android:endColor="progressColor"
                    android:angle="0"
                />
            </shape>
        </clip>
    </item>

</layer-list>

在代码中将其设置为您的进度条

 // Get the Drawable custom_progressbar                     
 Drawable customDrawable= res.getDrawable(R.drawable.custom_progressbar);
 // set the drawable as progress drawavle
 progressBar.setProgressDrawable(customDrawable);

你可以这样试试:

<?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>
            <solid android:color="@color/seekbar_background" />

            <stroke
                android:width="@dimen/seekbar_background_border"
                android:color="@android:color/transparent" />
        </shape>
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <solid android:color="@color/seekbar_progress" />
            </shape>
        </clip>
    </item>

</layer-list>

进度条使用包含多个图层的图层列表。你需要背景进展。希望这对你有帮助:)

将这行代码添加到您的进度条中 XML。

android:progressBackgroundTint="#ReplaceThisWithYourColor"

对我有用。