If I put simple HTML formatting tags, such as <b>...</b> into a string resource and display the string in a TextView, the expected formatting is applied. But how can I do this if I build up my own String and display it? If I do something like String str = "This is <b>bold</b>";, the actual tags get displayed -- not the expected bolding.
Do I have to run the string through some other method to cause the tags to be recognized as tags?
In Android, the most common way to show a text is by TextView element. The whole text in the TextView is easy to make clickable implementing the onClick attribute or by setting an onClickListener to the TextView.
htmlToTextView. setText(HtmlCompat. fromHtml(htmlText, 0)); In the above code we are taking HTML data from fromHtml() and appending to textview using setText() .
Text styling is one of the important aspects when it comes to enhancing the UI of an Android application. In Android, we can change the size, color, weight, style, etc of a text and make the text more attractive and appealing.
You have to use Html#fromHtml
String input = "<b>bold</b>";
myTextView.setText(Html.fromHtml(input));
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