Is it possible to have multiple styles inside a TextView?

后端 未结 18 1842
醉梦人生
醉梦人生 2020-11-21 17:34

Is it possible to set multiple styles for different pieces of text inside a TextView?

For instance, I am setting the text as follows:

tv.setText(line         


        
18条回答
  •  感情败类
    2020-11-21 17:57

    Here is an easy way to do so using HTMLBuilder

        myTextView.setText(new HtmlBuilder().
                        open(HtmlBuilder.Type.BOLD).
                        append("Some bold text ").
                        close(HtmlBuilder.Type.BOLD).
                        open(HtmlBuilder.Type.ITALIC).
                        append("Some italic text").
                        close(HtmlBuilder.Type.ITALIC).
                        build()
        );
    

    Result:

    Some bold text Some italic text

提交回复
热议问题