【问题标题】:When is indeterminate progressbar coming to Android Support Library不确定的进度条何时进入 Android 支持库
【发布时间】:2016-02-07 08:38:41
【问题描述】:

我的应用程序 UI 是使用 Android 支持库构建的,但目前没有我的应用程序真正需要的(中间)进度条的 AppCompat 版本。

我宁愿不使用任何第三方库来实现材料设计进度条,所以我想知道是否有人知道为什么它不包含在支持库中,以及是否有任何迹象表明它到达(和什么时候)。

【问题讨论】:

  • 我投票结束这个问题,因为它是关于第三个图书馆可能的未来功能及其预计到达时间。
  • ETA 是什么意思?
  • ETA:“预计到达时间”
  • 您的问题不是一个实际的编程问题,可以以适当的实用方式回答。它在问为什么一家公司发布了一个没有你希望它拥有的功能的库,如果说公司正在考虑添加它。这纯粹是推测性的。任何人回答这个问题的唯一方法是,如果谷歌的某个人决定来这里告诉你为什么他们认为这不重要。也许您可以重新编写您的问题,准确发布您想要实现的目标(带有屏幕截图)、您将在 nonAppCompat 版本中编码的内容以及其他开发人员建议的解决方法。
  • 我不是要求任何人猜测任何事情。我想知道支持库是否有一些未来功能列表和/或何时计划。

标签: android material-design android-support-library android-appcompat android-progressbar


【解决方案1】:

材质组件库

您可以将 LinearProgressIndicatorandroid:indeterminate="true" 属性一起使用:

<com.google.android.material.progressindicator.LinearProgressIndicator
    android:indeterminate="true"
    app:indicatorColor="?attr/colorPrimary"/>

您还可以使用不同的颜色:

<com.google.android.material.progressindicator.LinearProgressIndicator
        android:indeterminate="true"
        app:indicatorColor="@array/progress_colors"
        app:indeterminateAnimationType="contiguous"/>

与:

  <integer-array name="progress_colors">
    <item>@color/...</item>
    <item>@color/....</item>
    <item>@color/....</item>
  </integer-array>

您还可以使用 CircularProgressIndicator 组件来设置循环进度指示器:

<com.google.android.material.progressindicator.CircularProgressIndicator
    android:indeterminate="true"
    app:indicatorColor="?attr/colorPrimary"/>

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


Jetpack 组合

对于1.0.x,您可以使用LinearProgressIndicatorCircularProgressIndicator

// Indeterminate
CircularProgressIndicator()
LinearProgressIndicator()

// Determinate
CircularProgressIndicator(progress = ..)
LinearProgressIndicator(progress = ..)

例子:

var progress by remember {  mutableStateOf(0.1f) }

LinearProgressIndicator(
    backgroundColor = Color.White,
    progress = progress,
    color = Blue
)

AppCompat

您可以使用带有 AppCompat 样式的ProgressBar

只需在你的布局中添加这个:

<ProgressBar
        style="@style/Base.Widget.AppCompat.ProgressBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        android:visibility="visible" />

如果您想要水平进度条,请使用:

  <ProgressBar
        style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
        android:layout_width="match_parent"
        android:layout_height="8dp"
        android:layout_marginTop="24dp"
        android:indeterminate="true"
        android:visibility="visible" />

他们关注官方资料guidelines

【讨论】:

  • 如何将其用作带有 webView 的操作栏中的中间进度条?
  • 想补充一点,这不适用于不确定的圆形条。他们缺少动画矢量drawable。
  • @Robert 任何提示如何为不确定的圈子做同样的事情?这是我使用 google-fu 可以获得的最佳结果之一。
  • @RichardLeMesurier 您可以尝试从 Chromium 中包含此实现。它不使用矢量可绘制对象:chromium.googlesource.com/android_tools/+/master/sdk/extras/…
  • 这个答案只描述了如何使用平台的原生进度条。在棒棒糖之前的设备上,您最终会看到一个未着色的全息进度条。这没有回答问题。
【解决方案2】:

这是一个老问题的答案,但我认为其他读者可能对此解决方案感兴趣:

支持库的较新版本 (26.1.+) 包含一个名为 CircularProgressDrawable 的类,该类实现了本机 Material indeterminate drawable 的确切外观。为了在布局中轻松使用它,您可以像这样构建MaterialProgressBar

public class MaterialProgressBar extends ProgressBar{
    // Same dimensions as medium-sized native Material progress bar
    private static final int RADIUS_DP = 16;
    private static final int WIDTH_DP = 4;

    public MaterialProgressView(Context context, AttributeSet attrs) {
        super(context, attrs);

        // The version range is more or less arbitrary - you might want to modify it
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP
                || Build.VERSION.SDK_INT > Build.VERSION_CODES.O_MR1) {

            final DisplayMetrics metrics = getResources().getDisplayMetrics();
            final float screenDensity = metrics.density;

            CircularProgressDrawable drawable = new CircularProgressDrawable(context);
            drawable.setColorSchemeColors(getResources().getColor(R.color.colorPrimary));
            drawable.setCenterRadius(RADIUS_DP * screenDensity);
            drawable.setStrokeWidth(WIDTH_DP * screenDensity);
            setIndeterminateDrawable(drawable);
        }
    }
}

【讨论】:

    【解决方案3】:

    我只是想改进 Gabriele Mariotti 先生使用样式的答案。

    1. 这样写样式

      <style name="infinite_progress_horizontal" parent="Widget.AppCompat.ProgressBar.Horizontal">
          <item name="android:layout_width">match_parent</item>
          <item name="android:layout_height">wrap_content</item>
          <item name="android:indeterminate">true</item>
      </style>
      
    2. 像这样与你的进度条一起使用。

      <ProgressBar style="@style/infinite_progress_horizontal" />
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多