如何在Android字符串中加粗部分文本

6
我想加粗一段文本,但我不知道该怎么做。这是我的文本:
<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". 

4个回答

7
只需要像这样使用 -
String sourceString = "<b>" + id + "</b> " + name; 
mytextview.setText(Html.fromHtml(sourceString));

如果您想编辑strings.xml中的字符串,可以按以下方式进行 -

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

你没有理解什么? - Narendra Singh
当我这样做:<resource> <string name="styled_welcome_message">我们很高兴地看到您。<b>非常</b></string> </resources>时,他忽略了文本的最后一部分“非常”,并未显示出来。 - Ali
你能展示一下你正在测试的字符串吗? - Narendra Singh

3

您可以在字符串资源中使用<b></b>标记(以及它们的<i><u>对应标记)。根据您使用字符串资源的位置和方式,将应用格式。


1
您可以使用 SpannableStringBuildernew StyleSpan(android.graphics.Typeface.BOLD) 对字符串的一部分进行格式化以使其变为粗体。您可以在这里获得帮助 here

0

你可以像下面这样使用HTML格式:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接