为什么以下代码不起作用?它适用于Toast但不适用于TextView.当我运行程序时,boldName不会显示为粗体,但当我将其设置为Toast时,它确实显示为粗体.有没有人有其他解决方案?
String boldName = "<b>" + name + "</b>";
Spanned conBold = Html.fromHtml(boldName);
chosen_contact.setText("You have chosen " + conBold + " as your contact.");
Run Code Online (Sandbox Code Playgroud) 我想为一个单词设置自定义字体,该单词出现在字符串中的任何位置.
例:海@abc你好吗?亲爱的朋友你好,你在哪里@abc
在上面的例子中,我必须为"abc"应用自定义字体.我尝试过Spannable类,但我无法得到它.
final TextView txtComments = (TextView)view.findViewById(R.id.tv_comments);
SpannableStringBuilder SS = new SpannableStringBuilder(alcomments.get(i));
SS.setSpan (new CustomTypefaceSpan("", tf), 0, SS.length(),Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
txtComments.setText(SS);
Run Code Online (Sandbox Code Playgroud)
但它影响整个字符串.请指导我如何实现它.
我想加粗“”文本的一部分,但我不知道这是我的文本:
<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".
Run Code Online (Sandbox Code Playgroud)