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

标签 android android-layout android-activity android-progressbar

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

<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>

我的进度条如下图所示

enter image description here
如何设置进度条灰色部分的颜色???

最佳答案

尝试查看一些教程 herehere .

在您的 drawable 中创建一个文件 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);

关于android - 在android中设置剩余进度条颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28315976/

相关文章:

java - Android - 如何在每次打开应用程序时启动完全相同的 Activity ?

android - 如何将 ZIP 文件导入 Android Studio?

Android:组织不同的构建目标/读取资源文件运行时

java - 向位图添加虚线边框

java - 提交的 EditText 不会相应地表现

java - 在微调器选择上加载不同的表单布局

Android:AlertDialog 在 fragment 中看起来不同

android - requestLocationUpdates 花费的时间太长

android - ImageView 不能正确居中缩小图像

android - 在广播接收器中使用共享首选项