如何在安卓中使用水平的“材料进度指示器”?

11

我已经使用了 "android.material.progressindicator" 来显示水平进度,但我无法听到我的 XML

<com.google.android.material.progressindicator.ProgressIndicator
                android:background="@color/grey"
                android:id="@+id/progressInd"
                style="@style/Widget.MaterialComponents.ProgressIndicator.Linear.Determinate"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:indeterminate="false"
                android:max="100"
                android:progress="30"
                android:progressDrawable="@drawable/bidding_progress" />

这里输入图片描述

1个回答

19

你可以使用:

<com.google.android.material.progressindicator.LinearProgressIndicator
    app:indicatorColor="?attr/colorPrimary"
    app:trackColor="@color/..."
    />

使用 progressIndicator.setProgressCompat((int) value, true); 来更新指示器中的值。

使用以下属性:

  • indicatorColor 设置指示器颜色
  • trackColor 设置轨道颜色
  • trackThickness 设置进度条高度

enter image description here

注意: 至少需要版本 1.3.0-alpha04


在SDK版本25中,我运行该应用程序时出现了崩溃。Logcat消息如下:"Before Android 4.1, method android.graphics.drawable.Drawable com.google.android.material.progressindicator.ProgressIndicator.getCurrentDrawable() would have incorrectly overridden the package-private method in android.widget.ProgressBar",但是这段代码在SDK 28上运行正常。请给我您的建议来解决这个问题。 - RaJ
@RaJ 你可以在 github repo 上提交一个问题。 - Gabriele Mariotti
好的,谢谢。最初,我设置了progressIndicator.setMin(0);现在我删除了那一行,现在它正常工作。 - RaJ
对于不确定的进度条:android:indeterminate="true" - mathematics-and-caffeine

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接