问题
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?
回答1:
It is possible to implement this behavior using the chipIcon
attribute and androidx.swiperefreshlayout.widget.CircularProgressDrawable
.
xml
app:chipIconWithProgress="@{viewModel.taskIsStarting ? null : @drawable/ic_play_arrow}"
and BindingAdapter
@BindingAdapter("chipIconWithProgress")
fun Chip.setChipIconWithProgress(item: Drawable?) {
chipIcon = item
?: CircularProgressDrawable(context!!).apply {
setStyle(CircularProgressDrawable.DEFAULT)
start()
}
}
来源:https://stackoverflow.com/questions/54536053/how-to-display-progress-drawable-animation-in-chip-material-component