I have just read that buttons (MaterialButton) (progress indicator material design) in Material Design, are able to hold a circular progress Indicator, as you can see in the attached picture

Bassically when you press the button remove text and show a progress indicator, but there is no clue about how to implement it, does anybody already deal with it?
it will be really appreciate any hint. Thanks
With the MaterialComponents library you can use the IndeterminateDrawable class to create a CircularProgressIndicator and apply it to a Button or the icon in a Button:
val spec =
CircularProgressIndicatorSpec(this, /*attrs=*/null, 0,
com.google.android.material.R.style.Widget_Material3_CircularProgressIndicator_ExtraSmall)
val progressIndicatorDrawable =
IndeterminateDrawable.createCircularDrawable(this, spec)
//...
button.setOnClickListener {
button.icon = progressIndicatorDrawable
}
With:
<com.google.android.material.button.MaterialButton
android:id="@+id/indicator_button"
style="@style/Widget.Material3.Button.OutlinedButton.Icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:text="Button"/>

With Compose you can use something like:
var progressIndicatorVisible by remember { mutableStateOf(false) }
Button(
onClick = {
scope.launch {
progressIndicatorVisible = true
// Just for example
delay(5000)
progressIndicatorVisible = false
}
},
modifier = Modifier.animateContentSize()){
if (progressIndicatorVisible) {
CircularProgressIndicator(
color = White,
strokeWidth = 2.dp,
modifier = Modifier.size(15.dp)
)
}
Text (
"Button",
modifier = Modifier.padding(start = if (progressIndicatorVisible) 8.dp else 0.dp)
)
}

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With