Android Question How to get the CornerRadius of a Button?

Jerryk

Active Member
Licensed User
Longtime User
I tried this code but an error occurs
B4X:
    Dim target As Object = Button1

    If GetType(target.As(View).Background) = "android.graphics.drawable.StateListDrawable" Then
        Dim sld As StateListDrawable
        sld = target.As(View).Background
        Dim jo As JavaObject = sld
        Dim drawable As Object = jo.RunMethod("getStatDrawable", Array(sld.State_Enabled))   ' error - java.lang.RuntimeException: Method: getStatDrawable not found in: android.graphics.drawable.StateListDrawable
        Private cd As ColorDrawable
        cd = drawable
        Dim jo1 As JavaObject = cd
        Log(jo1.GetField("cornerRadius"))
    End If
 

William Lancee

Well-Known Member
Licensed User
Longtime User
Try using the view directly like this:

B4X:
    Root.LoadLayout("MainPage")        'Panel1 has designer corner radius 15 - this is scaled by designer
    Log(GetType(Panel1.Background)) '    anywheresoftware.b4a.objects.drawable.ColorDrawable$GradientDrawableWithCorners
    
    Private cd As ColorDrawable = Panel1.Background
    Dim jo1 As JavaObject = cd
    Log(jo1.GetField("cornerRadius"))        '    26.0 pixels
 
Upvote 0

Jerryk

Active Member
Licensed User
Longtime User
Try using the view directly like this:

B4X:
    Root.LoadLayout("MainPage")        'Panel1 has designer corner radius 15 - this is scaled by designer
    Log(GetType(Panel1.Background)) '    anywheresoftware.b4a.objects.drawable.ColorDrawable$GradientDrawableWithCorners
   
    Private cd As ColorDrawable = Panel1.Background
    Dim jo1 As JavaObject = cd
    Log(jo1.GetField("cornerRadius"))        '    26.0 pixels
I am looking for a solution for Button not for Panel. Button.Background has: android.graphics.drawable.StateListDrawable
 
Upvote 0
Top