Is there a way to use variables in this situation? I want this code:
String str = "test";
Html.fromHtml("test <.bold> str <./bold> test");
to make:
test test test
but instead it makes:
test str test
Thanks
What about this?
String str = "test";
textView.setText( Html.fromHtml("test <bold>" + str + "</bold> test") );
or for a more difficult solution, you can use java's replaceAll for replacing strings defined with regular expression.
kotlin version using an extension function with Android SDK deprecation validation
@Suppress("deprecation")
fun String.fromHtml(): Spanned = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(this, Html.FROM_HTML_MODE_LEGACY)
} else {
Html.fromHtml(this)
}
val str = "test"
textView.text = "test <bold>$str</bold> test".fromHtml()
<.bold>is not valid HTML and is not honored byHtml.fromHtml().