GradientDrawable not provided

Dominex

Active Member
Licensed User
Longtime User
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.
 
Upvote 0

Dominex

Active Member
Licensed User
Longtime User
Upvote 0

Dominex

Active Member
Licensed User
Longtime User
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
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
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.

Best regards.

EDIT: 2012.12.18
updated the zip file
 

Attachments

  • Demo.jpg
    Demo.jpg
    54.3 KB · Views: 377
  • GradientDrawable.zip
    9.5 KB · Views: 293
Last edited:
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Cool.

A couple of things:

1- Selecting "Line" crashes the app with a java.lang.NullPointerException error.

2- Selecting "Rings" shows nothing.

I tried that on JB 4.2.1

Nice code by the way.
 
Upvote 0
Top