Is it possible to have multiple styles inside a TextView?

后端 未结 18 1849
醉梦人生
醉梦人生 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:53

    Slightly off-topic, but I found this too useful not to be mentioned here.

    What if we would like to read the the Html text from string.xml resource and thus make it easy to localize. CDATA make this possible:

    
      Autor: Mr Nice Guy
    Contact: myemail@grail.com
    Copyright © 2011-2012 Intergalactic Spacebar Confederation ]]>

    From our Java code we could now utilize it like this:

    TextView tv = (TextView) findViewById(R.id.myTextView);
    tv.setText(Html.fromHtml(getString(R.string.my_text))); 
    

    I did not expect this to work. But it did.

    Hope it's useful to some of you!

提交回复
热议问题