Android Textview fromHtml粗体标记未正确显示
我正在使用fromHtml来表示一些单词,但没有正确显示。对不起,我的英语不好Android Textview fromHtml粗体标记未正确显示,android,html,textview,Android,Html,Textview,我正在使用fromHtml来表示一些单词,但没有正确显示。对不起,我的英语不好 Typeface tfArial = Typeface.createFromAsset(getAssets(), "arialtur.otf"); String yazi="Deneme "+"<strong>"+"must be bold"+"</strong>"+" kayıt."; Spanned text1 = Html.fromHtml(yazi);
Typeface tfArial = Typeface.createFromAsset(getAssets(), "arialtur.otf");
String yazi="Deneme "+"<strong>"+"must be bold"+"</strong>"+" kayıt.";
Spanned text1 = Html.fromHtml(yazi);
TextView aa= (TextView) findViewById(R.id.metin1);
TextView ab= (TextView) findViewById(R.id.metin2);
aa.setText(text1);
aa.setTypeface(tfArial);
ab.setText("Non arial font");
Typeface tfArial=Typeface.createFromAsset(getAssets(),“arialtur.otf”);
字符串yazi=“Deneme”+”“+”必须为粗体“+”“+”kayıt.”;
span text1=Html.fromHtml(yazi);
TextView aa=(TextView)findViewById(R.id.metin1);
TextView ab=(TextView)findViewById(R.id.metin2);
aa.setText(text1);
aa.设置字体(tfArial);
ab.setText(“非arial字体”);
屏幕截图
HTML标记不是“样式”标记。这里只是为了表明内容的重要性。
的默认样式依赖于web引擎实现
您可以从以下两个链接获得一些信息:
如果您想要粗体文本,请尝试使用
而不是
。您可以通过以下几种方式执行此操作:
Typeface tfArial =Typeface.createFromAsset(getAssets(),"arialtur.otf");
String yazi="Deneme <strong> must be bold </strong> kayıt.";
// OR String yazi="Deneme <b> must be bold </b> kayıt.";
TextView aa= (TextView) findViewById(R.id.metin1);
TextView ab= (TextView) findViewById(R.id.metin2);
aa.setText(Html.fromHtml(yazi));
aa.setTypeface(tfArial);
//OR aa.setTypeface(tfArial,Typeface.BOLD);
ab.setText("Non arial font");
Typeface tfArial=Typeface.createFromAsset(getAssets(),“arialtur.otf”);
String yazi=“Deneme必须是粗体的”kayıt.”;
//或字符串yazi=“Deneme必须是粗体kayıt.”;
TextView aa=(TextView)findViewById(R.id.metin1);
TextView ab=(TextView)findViewById(R.id.metin2);
aa.setText(Html.fromHtml(yazi));
aa.设置字体(tfArial);
//或aa.setTypeface(tfArial,Typeface.BOLD);
ab.setText(“非arial字体”);
例如:
使用strong标记
Deneme必须是粗体的kayıt
使用b标记
Deneme一定很大胆kayıt试试这个
String message ="Deneme "+"<b>"+"must be bold"+"</b>"+" kayıt.";
aa.setText(Html.fromHtml(message));
String message=“Deneme”+“+”必须为粗体“+”+“kayıt.”;
aa.setText(Html.fromHtml(message));
您也可以使用HTML标记从XML中执行相同的操作,如果资源字符串中有
标记,则可以将文本包装在和]>
中,即:
<string name="textWithBold"><![CDATA[<b>BoldText</b>]]></string>
为什么它“没有正确显示”?实际的问题是什么?斜体显示,屏幕截图附加。你确定你的字体支持粗体吗?试试Typeface TfArialBold=Typeface.create(tfArial,Typeface.bold);并使用aa.setTypeface(tfArialBold);我有一个常规字体,粗体字体必须在单独的文件中,或者每个文件中?您现在必须检查您的自定义字体是否正确创建了“粗体”版本。
textView.setText(Html.fromHtml(getString(R.string.textWithBold)));