【问题标题】:Custom style for dynamically generated ProgressBars/Widgets动态生成的 ProgressBars/Widgets 的自定义样式
【发布时间】:2014-04-08 00:05:26
【问题描述】:
【问题讨论】:
标签:
android
android-widget
android-progressbar
android-styles
【解决方案1】:
原来我想要的是一个 Drawable。
这有帮助:http://www.learn-android-easily.com/2013/05/custom-progress-bar-in-android.html
后来我发现了这个,这也有帮助:http://www.learn-android-easily.com/2013/05/custom-progress-bar-in-android.html
我在我创建的新文件夹中自定义了一个 XML 文件:res/drawable/custombar.xml,然后像网站一样对其进行自定义:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<corners
android:radius="5dip"
/>
<gradient
android:angle="270"
android:centerColor="#ff5a5d5a"
android:centerY="0.5"
android:endColor="#ff747674"
android:startColor="#ff9d9e9d" />
</shape>
</item>
<!-- Define the progress properties like start color, end color etc -->
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="5dip"/>
<gradient
android:angle="0"
android:endColor="#ff009900"
android:startColor="#ff000099" />
</shape>
</clip>
</item>
然后将其设置为我的 Activity 中的 ProgressBar,如下所示:
ProgressBar bar = new ProgressBar(this, null, android.R.style.Widget_ProgressBar_Horizontal);
bar.setProgressDrawable(getResources().getDrawable(R.drawable.custom_progressbar));
希望这可以帮助一些人。