Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何解析textview字体中的字符串值?_Android_Textview_Typeface - Fatal编程技术网

Android 如何解析textview字体中的字符串值?

Android 如何解析textview字体中的字符串值?,android,textview,typeface,Android,Textview,Typeface,我创建了简单的文本视图应用程序。它工作正常,我需要在文本视图中解析字符串值。因为我有一个XML文件,所以我的XML文件包含一些空标记,如果我读取该空标记,我需要在文本视图中使用粗体视图例如:这是我的标记如果我读取此标记,我希望在文本视图中添加粗体视图,因此我尝试在文本视图中添加粗体视图 xml文件: <text> <![CDATA[<p style="text-align: center;"> <span style="color:#FFFFFF;

我创建了简单的文本视图应用程序。它工作正常,我需要在文本视图中解析字符串值。因为我有一个XML文件,所以我的XML文件包含一些空标记,如果我读取该空标记,我需要在文本视图中使用粗体视图例如:这是我的标记
如果我读取此标记,我希望在文本视图中添加粗体视图,因此我尝试在文本视图中添加粗体视图

xml文件:

      <text>
<![CDATA[<p style="text-align: center;">
<span style="color:#FFFFFF;">
<strong>
<span style="font-size:30px;">
<span style="font-family:georgia,serif;">
<span style="color: rgb(0, 128, 128);">
welcome </span>
</span>
</span>

</strong>
</span></p>
]]>
                </text>
正在尝试在文本视图中添加粗体视图:

TextView txt = (TextView)findViewById(R.id.sample);

        txt.setBackgroundColor(Color.parseColor(color));

        txt.setTypeface(null, bod);
此行我正在尝试分析该值:

txt.setTypeface(null, bod);

setTypeFace
需要一个
int
作为参数(不是字符串)

所以你可以这样做:

txt.setTypeFace(txt.getTypeface(),Typeface.BOLD);
或者,作为替代方案:

int bod = Typeface.NORMAL;
if (Bold_value.getLength() > 0) {
            //Style();
            bod = Typeface.BOLD;
}
txt.setTypeFace(txt.getTypeface(),bod);

(并保持当前字体,而不是传递null)

您的数据看起来很像html,您可以使用:

myTextView.setText(Html.fromHtml(<html string>))
myTextView.setText(Html.fromHtml())

我已经试过你的第二个,但我在这行中出错了为什么?Style.BOLD和NORMAL错误:NORMAL无法解析或不是字段,BOLD无法解析或不是字段组。。。对不起,我弄错了。使用字体而不是样式(我修正了我的帖子)
myTextView.setText(Html.fromHtml(<html string>))