简体   繁体   中英

how to bold a part of text Android String

我想加粗“”文本的一部分,但我不知道这是我的文字:

<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". 

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>

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.

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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM