Android Question Button problems with gradient fill background

Lakhtin_V

Active Member
Licensed User
Longtime User
If I use rectangular buttons and a simple background color, I have no problem. If I use a button with a gradient fill and round corners there are problems. Sometimes the buttons are displayed incorrectly. I can not understand the reason for this problem.
upload_2018-11-13_17-41-12.png
 

MarkusR

Well-Known Member
Licensed User
Longtime User
i guess it belongs ̶c̶̶a̶̶s̶̶c̶̶a̶̶d̶̶i̶̶n̶̶g̶̶ style s̶̶h̶̶e̶̶e̶̶t̶̶s̶̶ ̶
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Do you define the Buttons in the code or in the Designer.
I suppose in the code, and you define a GradientDrawable object and you use the same for several Buttons with different dimensions, you need to define one GradientDrawable for each Button.
 
Upvote 0
D

Deleted member 103

Guest
With this code should work.
B4X:
Public Sub DrawButton(btn As Button, Color1 As Int, Color2 As Int)
    Dim dr As GradientDrawable
    dr.Initialize("TOP_BOTTOM", Array As Int(Color1, Color2))
    dr.CornerRadius = 10dip
    btn.Background = dr
End Sub
 
Upvote 0

Lakhtin_V

Active Member
Licensed User
Longtime User
B4X:
Sub Globals
    ....
    Public gdUPnav As GradientDrawable, gdDOWNnav As GradientDrawable, gdUPevent As GradientDrawable, gdDOWNevent As GradientDrawable
    ....
End Sub

Sub Activity_Create(FirstTime As Boolean)
    ....
    gdUPnav.Initialize("BL_TR", Main.clrNavUP)
    gdUPnav.CornerRadius=Main.Rad
    gdDOWNnav.Initialize("BL_TR", Main.clrNavDOWN)
    gdDOWNnav.CornerRadius=Main.Rad
    gdUPevent.Initialize("BL_TR", Main.clrEventUP)
    gdUPevent.CornerRadius=Main.Rad
    gdDOWNevent.Initialize("BL_TR", Main.clrEventDOWN)
    gdDOWNevent.CornerRadius=Main.Rad
    .....
End Sub

    ....
    btn.Initialize("btnZvonok")
    str="Звонок консультанту"
    btn.Text=str
    btn.TextSize=Main.fSred
    btn.Background=gdUPevent
    btn.TextColor=Colors.DarkGray
    Activity.AddView(btn, 3%x, 76%y, 37%x, 10%y)
    ....

Thank you Klaus
Do you recommend to describe each button individually?

B4X:
    ....
    btn.Initialize("btnZvonok")
    str="Звонок консультанту"
    btn.Text=str
    btn.TextSize=Main.fSred
    gdUPevent.Initialize("BL_TR", Main.clrEventUP)
    gdUPevent.CornerRadius=Main.Rad
    btn.Background=gdUPevent
    btn.TextColor=Colors.DarkGray
    Activity.AddView(btn, 3%x, 76%y, 37%x, 10%y)
    ....
 
Upvote 0
Top