I have a AlertDialog that has multiple lines of text. I am looking to have a different color for each line of text. Any ideas on how one would go about this? Is it possible to set a span foreground color to a string variable?
API 30
// Create Material Dialog
MaterialAlertDialogBuilder dialogBuilder = new MaterialAlertDialogBuilder(MainActivity.this, R.style.AlertDialogTheme);
dialogBuilder.setTitle(getString(R.string.alert_dialog_title));
SpannableString string = new SpannableString(
"Text: " + variable1 +
"\n\nText: " + variable2);
string.setSpan(new ForegroundColorSpan(Color.RED), 0, string.length(), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
dialogBuilder.setMessage(string);
dialogBuilder.show();