android - 更改android中进度条的颜色

标签 android progress-bar

我正在尝试更改水平进度条的颜色,但它没有改变。我做了一些谷歌搜索,并浏览了你网站上给出的一些例子。但我没有成功准确地改变颜色。 我使用了 progressBar.setProgressDrawable(Drawable d) 但它设置了整个进度条 View 的背景颜色,而不是仅设置进度条本身的背景颜色。

请任何人帮助我。

谢谢

最佳答案

您好,我正在我的项目中使用这段代码。我希望它对你有用。

//在布局文件中创建 ProgressBar。

    <ProgressBar
     android:id="@+id/yourid"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:progressDrawable="@drawable/slider"   
           />

//在您的 drawable 文件夹中创建名为 slider 的 .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:drawable="@drawable/grey_bar_music"/>
    <item android:id="@android:id/progress">
        <clip android:drawable="@drawable/blue_bar_music" />
    </item>
</layer-list>

//grey_bar_music ->Background image name for  your progressbar.
//blue_bar_music->Progress bar change color using this image when it start from 0.

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

相关文章:

JAVA单行字符进度条在NetBeans输出窗口中有效,但在CMD中无效

Android - 如何实现嵌套按钮

android - ConstraintSet动画中引用 View 宽度为wrap_content时 View 的平移动画

安卓打包问题

html - 进度条上的边框图像切片效果?

c# - 我们如何使用 FtpWebRequest 显示上传进度条

c++ - 制作控制台进度条? ( Windows )

Android - 下载文件时显示进度条

android - Material Design 中的 ActionBar 弹出窗口

android - 使用 JobScheduler 代替 BroadcastReceiver 和 Service