java - android:带有自定义颜色的默认不确定进度条的xml

标签 java android user-interface

<分区>

我需要制作一个不确定的进度条,它与默认小部件相同,只是颜色不同。我无法使用着色,因为我需要 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 方库解决了它:

https://github.com/DreaminginCodeZH/MaterialProgressBar

关于java - android:带有自定义颜色的默认不确定进度条的xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32889366/

相关文章:

android - 如何在模拟器中升级 Android 的 Webview (Android 5)

java - 我需要标准化位图并将其存储在 TensorImage 中。有什么办法可以做到这一点吗?

java - SharedPreferences getSharedPreferences 总是返回以前的值,即使它已被更改

java - 如何使按钮从第一个 JTabbedPanel 移动到下一个?

java - 模型驱动的架构值得吗?工具的最新技术水平如何?

Java Swing 复选框

perl - 我应该为 Perl GUI 使用 Perl/Tk、Tcl::Tk 还是 Tkx?

matlab - 在 Matlab GUI GUIDE 中更改工具栏图标

java - 输出大量数据最快的方法是什么?

java - 按住键后做某事并在释放和按下时重复