我创建了一个扩展 MaterialButton 的自定义视图,它在加载时将可绘制对象替换为 CircularProgressIndicator。
但是,当我用 CircularProgressIndicator 替换可绘制对象时,iconGravity 不再起作用。我看不出我做错了什么。
我已经能够将课程归结为:
class LoadingButton constructor(context: Context) : MaterialButton(context) {
private val progressIndicatorDrawable by lazy {
val progressIndicatorSpec = CircularProgressIndicatorSpec(context, null, 0, R.style.Widget_MaterialComponents_CircularProgressIndicator_ExtraSmall)
progressIndicatorSpec.indicatorColors = intArrayOf(getColor(context, R.color.white))
IndeterminateDrawable.createCircularDrawable(context, progressIndicatorSpec).apply {
setVisible(true, true)
}
}
init {
// the following drawable is aligned to the start of the view (incorrect).
icon = progressIndicatorDrawable
// the following drawable is aligned to the start of the text (correct).
// icon = DrawableUtil.getDrawable(context, R.drawable.icon_delete)
text = "Delete"
iconGravity = ICON_GRAVITY_TEXT_START
}
}
我正在使用这个依赖
// I've also tried 1.5.0-alpha02
implementation "com.google.android.material:material:1.3.0"