很简单的问题:
我有一些 TextView
TextView textView = (TextView) findViewById(R.id.textView1);
我设置样式文本(使用
<b>
标签或任何其他标签)textView.setText(Html.fromHtml("Simple text. <b>Bold text</b>. Simple text."));
问题:当我调用 textView.getText()
时我收到 Simple text. Bold text. Simple text.
. <b>
标签以某种方式消失了。
如何从 TextView 中检索文本及其格式?
最佳答案
@Wand Maker 的假设(见有问题的评论)是正确的
以下代码有效:
TextView textView = (TextView) findViewById(R.id.textView1);
textView.setText(Html.fromHtml("Simple text. <b>Bold text</b>. Simple text."), TextView.BufferType.EDITABLE);
String almostSameText = Html.toHtml(tv.getEditableText()).toString();
结果是:<p>Simple text. <b>Bold text</b>. Simple text</p>
关于android - 如何从 TextView 获取样式文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17491126/