本文介绍了如何在芯片材料组件中显示进度可绘制动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

根据官方行动芯片的设计文档,我们应该能够向芯片添加进度状态.遗憾的是,开发文档根本没有提及.是否有人设法弄清楚如何实现显示在此处?

According to the official Design docs for Action Chips, we are supposed to be able to add a progress state to chips. Sadly, the Development docs don't mention this at all. Has anyone managed to figure out how to achieve the effect shown here?

推荐答案

您可以使用材料组件库和Chip组件.

You can use the Material Components Library and the Chip component.

在布局中使用:

    <com.google.android.material.chip.Chip
        android:id="@+id/chip"
        style="@style/Widget.MaterialComponents.Chip.Action"
        app:iconStartPadding="2dp"
        ../>

然后将库提供的ProgressIndicator用作chipIcon:

   ProgressIndicatorSpec progressIndicatorSpec = new ProgressIndicatorSpec();
    progressIndicatorSpec.loadFromAttributes(
            this,
            null,
            R.style.Widget_MaterialComponents_ProgressIndicator_Circular_Indeterminate);
    progressIndicatorSpec.circularInset = 1; // Inset.
    progressIndicatorSpec.circularRadius =
            (int) dpToPx(this, 8); // Circular radius is 8 dp.
    IndeterminateDrawable progressIndicatorDrawable =
            new IndeterminateDrawable(
                    this,
                    progressIndicatorSpec,
                    new CircularDrawingDelegate(),
                    new CircularIndeterminateAnimatorDelegate());


    Chip chip = findViewById(R.id.chip);
    chip.setChipIcon(progressIndicatorDrawable);

使用此util方法:

public static float dpToPx(@NonNull Context context, @Dimension(unit = Dimension.DP) int dp) {
    Resources r = context.getResources();
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics());
}

您可以自定义颜色和所有其他属性:

You can customize the colors and all other attributes:

progressIndicatorSpec.indicatorColors = getResources().getIntArray(R.array.progress_colors);
progressIndicatorSpec.growMode = GROW_MODE_OUTGOING;

注意:这至少需要版本 1.3.0-alpha02 .

Note: this requires at least the version 1.3.0-alpha02.

这篇关于如何在芯片材料组件中显示进度可绘制动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 15:04