【发布时间】:2021-11-01 01:25:44
【问题描述】:
我创建了一个扩展 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"
【问题讨论】:
-
这似乎是一个错误。您可以使用 compose 作为解决方法吗?
-
我必须调查一下。我还没有任何撰写的经验。
-
就像其他人建议的那样,这似乎是材料组件库中的一个错误,所以我报告了一个问题:github.com/material-components/material-components-android/…
标签: android material-components-android material-components progress-indicator android-gravity