TextView secondTextView = new TextView(this);
Shader textShader=new LinearGradient(0, 0, 0, 20,
new int[]{Color.GREEN,Color.BLUE},
new float[]{0, 1}, TileMode.CLAMP);
secondTextView.getPaint().setShader(textShader);
The above particular code giving me green shade at the top and blue as text color but my requirement is absolutely in reverse order all i need is green color shade from the bottom and blue as text color. can someone please help me out to achieve this.
Hope this will work for you.
Shader myShader = new LinearGradient(
0, 0, 0, 100,
Color.WHITE, Color.BLACK,
Shader.TileMode.CLAMP);
secondTextView.getPaint().setShader(myShader);
Related
My goal is to fill shade the outer parabola when its downward but when i used paint that's the output.
My Code
Paint lineFill = new Paint();
lineFill.setAlpha(200);
lineFill.setShader(new LinearGradient(0, 0, 0, 250, Color.WHITE, Color.GREEN, Shader.TileMode.MIRROR));
series1Format.setFillPaint(lineFill);
I know I can create with LinearGradient, but I couldn't figure out how to create gradient from inside out.
I want to create something like this, and I want to control the size and the angle of the gradient.
I created this gradient with the code below.
linearGradient = new LinearGradient(0, 0, 0, h,
new int[]{0xffffffff, 0xffffffff, 0x00ffffff, 0x00ffffff, 0xffffffff, 0xffffffff},
new float[]{0, 0.30f, 0.45f, 0.55f, 0.7f, 1.0f}, Shader.TileMode.CLAMP);
How is it possible to create gradient for dynamic number in Android app?
E.g. TextView or Button with text is used.
(simple solution is a favorite)
Try this
TextView Textview1 = new TextView(this);
Shader textShader=new LinearGradient(0, 0, 0, 20,
new int[]{Color.GREEN,Color.BLUE},
new float[]{0, 1}, TileMode.CLAMP);
Textview1.getPaint().setShader(textShader);
It's possible, just create a drawable file, with a gradient:
<shape>
<gradient android:startColor=""
android:endColor=""
android:angle=""/>
</shape>
and point it in the
<TextView ...
android:textColor="#drawable/yourdrawablename"/>
or programmatically like this :
tv.setTextColor(R.drawable.yourdrawablename);
Use Shader and LinearGradient in android
TextView textview = new TextView(this);
Shader shader= new LinearGradient(0, 0, 0,20,new int[]{Color.WHITE,Color.GRAY},new float[]{0, 1}, TileMode.MIRROR);
textview.getPaint().setShader(shader);
I have a ShapeDrawable Object in my class in the form of an arc.
ShapeDrawable progressArc = new ShapeDrawable(new ArcShape(120, 12));
Now I would like to use a radial gradient effect on the color and also display just a ring instead of a filled arc. Does the Android SDK provide such a feature?
Currently using the below code, I get a gradient on the circle.
progressArc.setIntrinsicHeight(500);
progressArc.setIntrinsicWidth(500);
Shader shader1 = new LinearGradient(5, -5, 35, 0, new int[] { 0xFF33B5E5,0xFFFFFFFF }, null, Shader.TileMode.MIRROR);
progressArc.getPaint().setShader(shader1);
progressArc.getPaint().setStrokeWidth(1);
progressArc.getPaint().setColor(Color.RED);
progressArc.getPaint().setStyle(Paint.Style.FILL_AND_STROKE);
You can use a SweepGradient to get a radial gradient:
Shader s = new SweepGradient(0, 0, new int[] { 0xFF33B5E5,0xFFFFFFFF }, null);
//or if you only use two colors:
Shader s = new SweepGradient(0, 0, 0xFF33B5E5, 0xFFFFFFFF);
To avoid filling, just use the Paint.Style.STROKE style, with appropriate strokeWidth.
I have this code:
LinearGradient backlg = new LinearGradient(0, 0, 10, 10,
new int[]{Color.BLACK, Color.BLACK, Color.BLUE, Color.BLUE},
new float[]{0,0.5f,.55f,1}, Shader.TileMode.REPEAT);
Which creates diagonal bands alternating between blue and black. They go from Bottom left to top right so here is my question, what do I change to make it go from top left to bottom right?
Is this what you mean:
LinearGradient backlg = new LinearGradient(0, 10, 10, 0,
new int[]{Color.BLACK, Color.BLACK, Color.BLUE, Color.BLUE},
new float[]{0,0.5f,.55f,1}, Shader.TileMode.REPEAT);
Checkout the [documentation][1] for that constructor. The first 4 parameters are the x,y coordinates for the start and end of the gradient line.
So if 0,0 is bottom left and 10,10 is top right, try going from 0,10 to 10,0.
[1]: http://developer.android.com/reference/android/graphics/LinearGradient.html#LinearGradient(float, float, float, float, int[], float[], android.graphics.Shader.TileMode)