Search code examples
androidtextviewandroid-textattributes

how to make a specific text on TextView BOLD


I don't know how to make a specific text on TextView become BOLD.

its like this

txtResult.setText(id+" "+name);

I want the output to be like this:

1111 neil

id and name are variables that I have retrieved the value from database, and I want to make the id to bold, but only the id so the name will not affected, I have no idea how to do this.


Solution

  • Just build your String in HTML and set it:

    String sourceString = "<b>" + id + "</b> " + name; 
    mytextview.setText(Html.fromHtml(sourceString));