Draw a character with color 2 on Android

I am trying to create a karaoke text animation in Textview. Something like that:

Karaoke text effect

To make it smooth, I want to find a way to draw a two-color symbol (for example, sin an image).

I found this link , but HalfColorSpan did not draw anything there.

Is there any way to achieve this?

P / S: I was thinking about LinearGradient, but this code only set the gradient to VERTICAL.

class HalfColorSpan extends CharacterStyle implements UpdateAppearance {
    private final static String TAG = "DrawableSpanTest.HalfColorSpan";
    @Override
    public void updateDrawState(TextPaint paint) {
        paint.setStyle(Paint.Style.FILL);
        Shader shader = new LinearGradient(0, 0, 0, 80, new int[]{PROCESSED_COLOR, UNPROCESSED_COLOR}, new float[]{0, 1},
                Shader.TileMode.CLAMP);
        paint.setShader(shader);
    }
}
+4
source share

Source: https://habr.com/ru/post/1628440/


All Articles