Is it possible to change the text color in a string to multiple colors in Java?

后端 未结 9 1850
暗喜
暗喜 2020-11-27 04:37

What I mean is, is it possible to change the text \"This text is blue\" to the color blue in a single string? There must be a way...



        
9条回答
  •  甜味超标
    2020-11-27 05:03

    A simple way to do it is to use HTML and set the text to the TextView programmatically.

    String text = "This text is white. This text is blue.";
    textView.setText(Html.fromHtml(text), BufferType.SPANNABLE);
    

提交回复
热议问题