Android Question How to apply Gradient and other properties to buttons

raphipps2002

Active Member
Licensed User
Longtime User
I am experimenting with creating buttons and labels using code rather than the Designer but cant fathom how to assign certain properties to say a button. Eg. CornerRadius on a button. The property does not exist.
I discovered this bit of code

B4X:
Dim Gradient1 As GradientDrawable
    Dim clrs(2) As Int
    clrs(0) = Colors.RGB(255,165,0)
    clrs(1) =  Colors.RGB(255,255,255)

    Gradient1.Initialize("TOP_BOTTOM",clrs)
    Gradient1.CornerRadius = 20dip

But how do you apply it to a button

Dim b as button?

button.xxxxxxxx = etc

Can you help please

Richard
 

Mahares

Expert
Licensed User
Longtime User
@richard: In addition to Erel's link, here is the code you were looking for:
B4X:
   Dim b as Button
  b.initialize("b")
 Dim Gradient1 As GradientDrawable
 Dim clrs(2) As Int
 clrs(0) = Colors.RGB(255,165,0)
 clrs(1) = Colors.RGB(255,255,255)
 Gradient1.Initialize("TOP_BOTTOM",clrs)  
Gradient1.CornerRadius = 20dip
b.Background= Gradient1
 
Upvote 0

raphipps2002

Active Member
Licensed User
Longtime User
Can you tell me the way of when pressing the button it changes color...like with a button on the designer?
 
Upvote 0
Top