I have a SpannableStringBuilder
object with a ClickableSpan
link like this,
SpannableStringBuilder ssb = new SpannableStringBuilder("Hi StackOverflow!");
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(@NonNull View widget) {
Toast.makeText(MainActivity.this, "Clicked", Toast.LENGTH_SHORT).show();
}
};
ssb.setSpan(clickableSpan, 3, 16, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
This works fine when I set it to a TextView
and after using textView.setMovementMethod(LinkMovementMethod.getInstance())
When I set the ssb
object to the MaterialAlertDialogBuilder
,
new MaterialAlertDialogBuilder(this)
.setTitle("My Dialog")
.setMessage(ssb)
.show();
It displays as a clickable link but cannot actually click it
I couldn't find a way to use setMovementMethod
for the message in MaterialAlertDialogBuilder
. Is there any way to make it clickable?
TextView
the same style just use in your TextView thestyle="?attr/materialAlertDialogBodyTextStyle"
orstyle="@style/MaterialAlertDialog.MaterialComponents.Body.Text"
– Sackman