Following code will set gradient on textview (not background, but text itself). But I need to change angle of this gradient, how to do it?
Shader textShader = new LinearGradient(0, 0, 0, textView.getPaint().getTextSize(),
        new int[]{context.getResources().getColor(R.color.color1), context.getResources().getColor(R.color.color2)},
        new float[]{0, 1}, Shader.TileMode.CLAMP);
textView.getPaint().setShader(textShader);
Thank you in advance.
final TextView myTextView = findViewById(R.id.my_text_view);
myTextView.post(new Runnable() 
    {
         @Override
            public void run() {
                int length = textView.getMeasuredWidth();
            float angle = 45; // specify angle in degrees here
            Shader textShader = new LinearGradient(0, 0, (int) (Math.sin(Math.PI * angle / 180) * length), 
                                    (int) (Math.cos(Math.PI * angle / 180) * length),
                                        new int[]{Color.BLUE, Color.GREEN, Color.GREEN, Color.BLUE, Color.RED, Color.GREEN, Color.BLUE, Color.RED},
    null, 
        Shader.TileMode.CLAMP);
        myTextView.getPaint().setShader(textShader);
            textView.invalidate();
            }
    });

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With