Round Button turns square when I change the color

chuck3e

Active Member
Licensed User
Longtime User
This post may be incorrect. I need to do more testing before pursuing it any further
-Chuck
 
Last edited:

barx

Well-Known Member
Licensed User
Longtime User
That is the correct behavior when simply setting the color in code. Either use the designer or I think you can use the colorDrawable object to set the radius.

Try something like this, though it is untested.

B4X:
Dim cd As ColorDrawable
   cd.Initialize(Colors.Blue, 5)
   
   btn1.Background = cd
 
Upvote 0

chuck3e

Active Member
Licensed User
Longtime User
barx and Erel,
Thanks for your replies. I will probably need that info sometime. However, I decided to redesign the way I want my buttons to work to avoid the situation and don't need your handy tips right now. You are so responsive to newbies like me and I can't tell you how refreshing that is. Thanks for your help. I know I will have more stupid...er...newbie questions forthcomming.
-Chuck
 
Upvote 0

diego

Member
Licensed User
Longtime User
Old thread I now, but I just saw this problem with one label. Tried your code @barx and it worked, thanks.

Though, in the help that appears when you write label.Color there is this text "If the current background is of type GradientDrawable or ColorDrawable the round corners will be kept" but my label is ColorDrawable as in the designer is created that way but when changing color by code, round corners are losen.
 
Upvote 0

diego

Member
Licensed User
Longtime User
thanks LucaMs, I said it first, with that code it works but the Color help-description seems to be wrong...
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
If use XUI
B4X:
Private Sub Corner(V As B4XView,Clr As Int)
    Dim Can As B4XCanvas
    
    Can.Initialize(v)
    Dim P As B4XPath
    P.InitializeRoundedRect(Can.TargetRect,10dip)
    Can.DrawPath(P,Clr,True,1)
    Can.Invalidate
    Can.Release
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…