Android Question Set Rectangle on Canvas to have rounded corners?

Mashiane

Expert
Licensed User
Longtime User
Hi

I kindly need some help please.

B4X:
Sub Button_GrayWhiteText(btn As Button, StrokeWidth As Int)
    Dim dr As ColorDrawable
    dr.Initialize(Colors.rgb(240,240,240), 1%x)
    btn.Background = dr
    btn.TextColor = Colors.white
    If StrokeWidth <> 0 Then
        Dim c As Canvas
        c.Initialize(btn)
        Dim R As Rect : R.Initialize(0, 0, btn.Width - StrokeWidth, btn.Height - StrokeWidth)
        c.DrawRect(R, Colors.black, False, StrokeWidth)
    End If
End Sub

This simple code makes the normal button gray with white text. if I specify a strokewidth other than 0, there is a border around the button. The border rectangle is however squared. How can I make that rectangle to have the 1%x rounded corners?

Thanks.
 
Top