0

I made this Icon in Photoshop, but now I want to make the gradiant in Android and use it as the Textcolor for a Textview

The colors and settings from Photoshop is:

Style: Linear

Angle: 90*

Colors: #00a8d9 (0%), #223595 (20%), #f1328f(40%), #ee3031(60%), #f9e63a(80%), #009958(100%)

The numbers in the parentes is the location value.

enter image description here

I have tried the following, but its only showing one color

LinearGradient linearGradient = new LinearGradient(20,30,40,50, new int[]    {Color.parseColor("#00a8d9"), Color.parseColor("#223595"), Color.parseColor("#f1328f"), Color.parseColor("#ee3031"), Color.parseColor("#f9e63a"), Color.parseColor("#009958")},new float[]{0,0,0,0,0,0},
    Shader.TileMode.REPEAT);
    textView.getPaint().setShader(linearGradient);

2 Answers2

0

I managed to replicate the gradient from the picture to the code with this solution:

     textView = (TextView) v.findViewById(R.id.fontcolorwhite);

    LinearGradient linearGradient = new LinearGradient(60,-70,60,70, new  int[]{Color.parseColor("#00a8d9"), Color.parseColor("#4244b8"), Color.parseColor("#f1328f"), Color.parseColor("#ee3031"), Color.parseColor("#fde92d"), Color.parseColor("#009e54")},null,
    Shader.TileMode.MIRROR);
    textView.getPaint().setShader(linearGradient);

Another problem is that the gradient dosn't look the same with different screen sizes. This will be in a another question

-1

You may Try this.

Try to set this as your view background colour and set colour as per your need.

 GradientDrawable rainbow = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
                    new int[] {Color.RED, Color.MAGENTA, Color.BLUE, Color.CYAN, Color.GREEN, Color.YELLOW, Color.RED});

textview.setBackground(rainbow);
Dipali Shah
  • 3,742
  • 32
  • 47