B4A Library [Class] Special Drawables

Two classes - circular Drawable and RectDrawable, each can be set with flat area in the center (or none).


  • screen.png
    20.5 KB · Views: 909
  • specialdrawables.zip
    8 KB · Views: 525
Last edited:

Roger Garstang

Well-Known Member
Licensed User
Longtime User
The manual shows passing an array of just two colors for the gradient, but you can pass more. I use it in my button function I've posted here a couple times:

Sub ButtonGradient(LightColor As Int, DarkColor As Int) As StateListDrawable
Dim ref As Reflector

   ' Define a GradientDrawable for Enabled state
   Dim gdwEnabled As GradientDrawable
   gdwEnabled.Initialize("TOP_BOTTOM", Array As Int(LightColor, Colors.White, DarkColor))
   gdwEnabled.CornerRadius = 15
   ' Define a GradientDrawable for Pressed state
   Dim gdwPressed As GradientDrawable
   gdwPressed.Initialize("TOP_BOTTOM",Array As Int(DarkColor, DarkColor, Colors.White, LightColor))
   ref.Target = gdwPressed
   ref.RunMethod4("setCornerRadii", Array As Object(Array As Float(10,15,10,15,10,15,10,15)), Array As String("[F"))
   ' Define a GradientDrawable for Disabled state
   Dim gdwDisabled As GradientDrawable
   gdwDisabled.Initialize("TOP_BOTTOM", Array As Int(Colors.LightGray, Colors.DarkGray))
   gdwDisabled.CornerRadius = 20
   ' Define a StateListDrawable
   Dim stdGradient As StateListDrawable
   stdGradient.AddState2(Array As Int(stdGradient.State_enabled, -stdGradient.State_Pressed), gdwEnabled)
   stdGradient.AddState(stdGradient.State_Pressed, gdwPressed)
   stdGradient.AddState(stdGradient.State_Disabled, gdwDisabled)
   Return stdGradient
End Sub


Licensed User
Longtime User
so you get the double gradient by using three colors (start,end start ) ? I'll try it, if true then this class is redundant...
Yes it works , so you can ignore the double gradient class.

Roger - thank you !
Last edited:

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Yes, from what I tested you can just give it however many colors you want and it uses them in order. There isn't a way of determining start/end positions though, so you have to double up colors (Like I did with my Dark Color above) and such to shift where the change starts.

And, your class isn't redundant...it can just be improved on now with new knowledge and less views needed, etc. I'd just modify it to use Shadow/Highlight colors like I did for my buttons (And how Windows Does it), so now they can pass it a color theme and the class handles all the 3D aspects.