如何从TextView的样式文本 [英] How to get styled text from TextView

查看:110
本文介绍了如何从TextView的样式文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很简单的问题:


  1. 我有一些的TextView

  1. I have some TextView

TextView textView = (TextView) findViewById(R.id.textView1);


  • 我设置样式的文本(与< B> 标签或任何其他标​​签)

  • I set styled text (with <b> tags or any other tags)

    textView.setText(Html.fromHtml("Simple text. <b>Bold text</b>. Simple text."));
    


  • 问题:当我打电话 textView.getText()我收到简单的文本。粗体文字。简单的文字。&LT; B&GT; 标签在一定程度上将消失

    Problem: when I call textView.getText() I receive Simple text. Bold text. Simple text.. <b> tags have disappeared somehow.

    我如何与它的格式检索的TextView文字?

    How can I retrieve text from TextView with its formatting?

    推荐答案

    @Wand Maker的假设(见问题评论)是正确的。

    @Wand Maker's assumption (see comments in question) was correct

    继code工作:

    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();
    

    结果是:&LT; P&GT;简单的文本。 &LT; B&GT;粗体文字&lt; / B&取代。简单的文字&lt; / P&GT;

    这篇关于如何从TextView的样式文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆