Search code examples
javaandroidtextview

Remove Bold from textview without changing other attributes


I use setTypeface to set a text bold (or italics, or other of the typeface attributes)

TextView tv = findViewById(R.id.label);
...
tv.setTypeface(null,Typeface.BOLD);
...

How do I remove only the bold attribute, without changing other attributes that might have been set so far?


Solution

  • tv.setTypeface(null,Typeface.NORMAL);
    

    This would set the style back to normal without changing color or size.

    But you can't mix bold/italic/underline text this way. If you specify BOLD, all of the text will be bold. If you want to mix the style of the text I suggest using HTML to style the text, and then use the following code.

    tv.setText(Html.fromHtml(yourStringAsHtml));