Ali
Ali

Reputation: 85

how to bold a part of text Android String

i want to bold a part of "" a text but i dont know how this my text:

<string name="apropos"> Le projet Marocherche : Bâtir au cœur d un portail professionnel, destiné aux entreprises marocaines, une création  conçue par des "professionnels pour des professionnels". 

Upvotes: 6

Views: 12551

Answers (4)

Kingsley Nwankwo
Kingsley Nwankwo

Reputation: 1

You can use the html format like below:

String str = "You are about to start a video consultation with Dr. "+doctor.lastname()+", press <b>Ok</b> to proceed"; 
textview.setText(Html.fromHtml(str);

Upvotes: 0

Mithun
Mithun

Reputation: 2075

You can use SpannableStringBuilder and new StyleSpan(android.graphics.Typeface.BOLD) to format a part of the string to be Bold. You can get help here

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1006819

You can use <b> and </b> tags in a string resource (along with their <i> and <u> counterparts). Depending on where and how you use the string resource, the formatting will be applied.

Upvotes: 3

Narendra Singh
Narendra Singh

Reputation: 4001

Just use like this -

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

If you want to edit string in strings.xml, you can do it as -

<resource>
<string name="styled_welcome_message">We are <b>so</b> glad to see you.</string>
</resources>

Upvotes: 7

Related Questions