问题描述:Android按钮使用HTML设置文本无效。
问题解决方法:
Button button = findViewById(R.id.button);
String htmlText = "HTML文本";
Spanned spannedText = Html.fromHtml(htmlText);
button.setText(spannedText);
val button: Button = findViewById(R.id.button)
val htmlText = "HTML文本"
val spannedText: Spanned = Html.fromHtml(htmlText)
button.text = spannedText
注意:从Android N(7.0)开始,按钮的文本属性默认不支持HTML标记。如果需要支持HTML标记,请使用上述方法。