Home > other >  ColorTrackText in compose
ColorTrackText in compose

Time:10-15

I want to write this type of text ,is this possible?

enter image description here

CodePudding user response:

Using enter image description here

CodePudding user response:

You can take the text and set it into another color.

    String text = "I want THIS and THIS to be colored";

    SpannableString ss = new SpannableString(text);
    SpannableStringBuilder ssb = new SpannableStringBuilder(text);

    ForegroundColorSpan fcsRed = new ForegroundColorSpan(Color.RED);
    ForegroundColorSpan fcsGreen = new ForegroundColorSpan(Color.GREEN);
    BackgroundColorSpan bcsYellow = new BackgroundColorSpan(Color.YELLOW);

    ssb.setSpan(fcsRed, 7, 11, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.setSpan(fcsGreen, 16, 20, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.setSpan(bcsYellow, 27, 34, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    ssb.append(" and this to be appended");

    textView.setText(ssb);

enter image description here

The link: https://gist.github.com/codinginflow/15a8b33c43183b12153a7a5e978da0de

  • Related