我正在尝试更改水平进度条的颜色,但它没有改变。我做了一些谷歌搜索,并浏览了你网站上给出的一些例子。但我没有成功准确地改变颜色。
我使用了 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/