The following code is available:

Spannable sp = new SpannableString("Hello"); sp.setSpan(new ForegroundColorSpan(Color.RED), 0, sp.length(), 0); textview.setText(sp, BufferType.SPANNABLE); 

How to add some more spannable to this text in the same textview?

    1 answer 1

    You are probably interested in the TextView append () method.

    Add the following three lines to the existing code:

     Spannable spannableString= new SpannableString(" world"); spannableString.setSpan(new ForegroundColorSpan(Color.YELLOW), 0, spannableString.length(), 0); textview.append(spannableString); 

    At the output we get a TextView with the text "Hello world", where "Hello" is red, "world" is yellow.

    • Thanks for the help, it helped. - Kirill
    • @ Kirill yes not for that. - ermak0ff