[英]Html.toHtml() is not parsing <small> tags
I'm trying to get back the text of a Button as a String, I set it previously: 我试图将Button的文本作为字符串取回,我之前对其进行了设置:
button.setText(Html.fromHtml("<sup><small>1</small></sup>/<sub><small>8</small></sub>"));
but, the String returned from Html.toHtml() is: 但是,从Html.toHtml()返回的String是:
<sup>1</sup>/<sub>8</sub>
How do I get the tag back? 如何获得标签?
To get the string: 要获取字符串:
SpannedString spannedString = new SpannedString(button.getText());
Html.toHtml(spannedString)
toHtml()
does not handle <small>
tags, nor any other tags that fromHtml()
turns into RelativeSizeSpan
objects. toHtml()
不处理<small>
标记,也不会处理fromHtml()
变成RelativeSizeSpan
对象的任何其他标记。 You would have to write your own Spanned
-to-HTML conveter. 您将必须编写自己的Spanned
HTML转换程序。
TextView tv = (TextView) findViewById(R.id.text);
tv.setText(Html.fromHtml(getResources().getString(R.string.test)));
Define string 'test' in strings.xml 在strings.xml中定义字符串“ test”
<string name="test"><![CDATA[<sup><small>1</small></sup>/<sub><small>8</small></sub>]]></string>
In your case simple put button.setText(Html.fromHtml(getResources().getString(R.string.test)));
在您的情况下,简单地放置button.setText(Html.fromHtml(getResources().getString(R.string.test)));
It worked for me. 它为我工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.