The argument Colors is an array so you can use more than 2 colors to create the gradient.
B4X:
Dim Gradient1 As GradientDrawable
Dim Clrs(3) As Int
Clrs(0) = Colors.Black
Clrs(1) = Colors.White
Clrs(2) = Colors.Black
Gradient1.Initialize("TOP_BOTTOM", Clrs)
The argument Colors is an array so you can use more than 2 colors to create the gradient.
B4X:
Dim Gradient1 As GradientDrawable
Dim Clrs(3) As Int
Clrs(0) = Colors.Black
Clrs(1) = Colors.White
Clrs(2) = Colors.Black
Gradient1.Initialize("TOP_BOTTOM", Clrs)
Thanks, this is very interesting, unfortunately not fully resolve my problem. I need that the Gradient is directed from the center towards all directions.
Erel in another post has provided the answer. Thanks Erel.
B4X:
Sub Activity_Create(FirstTime As Boolean)
Dim GD As GradientDrawable
GD.Initialize("TOP_BOTTOM", Array As Int(Colors.White, Colors.Black))
Activity.Background = GD
SetRadialGradient(GD, Activity.Height/2)
End Sub
Sub SetRadialGradient(GD As GradientDrawable, radius As Float)
Dim r As Reflector
r.Target = GD
r.RunMethod2("setGradientType", 1, "java.lang.int")
r.RunMethod2("setGradientRadius", radius, "java.lang.float")
End Sub
Attached you find a small demo program for GradientDrawables you can play with.
You can change :
- corner radius
- gradiend shape
- gradient type
- gradient orientation
- gradient radius
- gradient center
About Rectangle Gradient, if you expect a gradient with a rectangular shape (rectangles changing colors) this is not supported in Android.