How to make some part of text bold and some part of text normal in both EditText and TextView

1.3k views Asked by At

I want to make something like

wow its cool app

in android. so that users can see a bold text in both TextView and EditText like WhatsApp. I don't know what to do. I searched and found something in which we can use HTML tags but some of the users don't know how to use that. Is there a way so that it is easy for users to make some part of text bold and remaining will normal.

Here is the image which will clear more

enter image description here

in this image, users can bold some part of text by enclosing that in *'s.

enter image description here

2

There are 2 answers

1
Gabe Sechan On

For you to make text bold? Place it in a StyleSpan with a bold style to it. For the user to make it bold? You'll have to provide some UI for them to do that, that isn't built in.

0
Subhash Khimani On

You have to use HTML code and set to textview or edittextview as following..

TextView textView = (TextView) findViewById(R.id.textView);
String first = "Hello what's up ";
String next = "<B>some bold text </B>";
textView.setText(Html.fromHtml(first + next));

if you want to add bold text after '' character then find that character from textview or edittextview and apply tag after '' this character and set text into textview and edittextview