我需要制作一个不确定的进度条,该进度条与默认窗口小部件相同,只是颜色不同。我不能使用着色,因为我需要从api 15+开始支持。
到目前为止,我的解决方案是使用自定义可绘制xml:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0"
android:toDegrees="360">
<shape android:shape="ring" android:innerRadiusRatio="3"
android:thicknessRatio="8" android:useLevel="false">
<size android:width="48dip" android:height="48dip" />
<gradient android:type="sweep" android:useLevel="false"
android:startColor="somecolor" android:centerColor="somecolor"
android:centerY="0.50" android:endColor="somecolor" />
</shape>
</rotate>
然后定义自定义可绘制对象:
<ProgressBar
android:id="@+id/customprogressbar"
android:layout_width="42dp"
android:layout_height="35dp"
android:layout_gravity="center"
android:visibility="gone"
android:indeterminateDrawable="@drawable/customprogressbardrawable"
style="@android:style/Widget.ProgressBar"
/>
这可以工作,但是看起来不像默认的进度条。我可以使用哪些默认设置-还是有更好的方法使进度条与默认小部件在所有方面都相同,只是颜色不同?
多谢您的回覆。对于任何有兴趣的人,我最终都使用第3方库解决了它:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句