Android Question setCornerRadii

yaniv hanya

Active Member
Licensed User
Hi
I use this

B4X:
Sub setCornerRadii(v As View, Rx_TopLeft As Float, Ry_TopLeft As Float, Rx_TopRight As Float, Ry_TopRight As Float, Rx_BottomRight As Float, Ry_BottomRight As Float, Rx_BottomLeft As Float, Ry_BottomLeft As Float)
    Dim jo As JavaObject = v.Background
    If v.Background Is ColorDrawable Or v.Background Is GradientDrawable Then
        jo.RunMethod("setCornerRadii", Array As Object(Array As Float(Rx_TopLeft, Ry_TopLeft, Rx_TopRight, Ry_TopRight, Rx_BottomRight, Ry_BottomRight, Rx_BottomLeft, Ry_BottomLeft)))
    End If
End Sub

in some apps it works and in some apps it crush and i get this log

Error occurred on line: 35 (LeaveRoomO)
java.lang.RuntimeException: Method: setCornerRadii not found in: android.graphics.drawable.ColorDrawable
at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:366)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:119)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at b4a.example.leaveroomo._createminbarline(leaveroomo.java:92)
at b4a.example.leaveroomo._fillpaylist(leaveroomo.java:118)
at b4a.example.leaveroomo._initialize(leaveroomo.java:56)
at b4a.example.main._menusubbtn_click(main.java:1802)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:5675)
at android.view.View$PerformClick.run(View.java:22641)
at android.os.Handler.handleCallback(Handler.java:836)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
line 35 is " jo.RunMethod("setCornerRadii", Array As Object(Array As Float(Rx_TopLeft, Ry_TopLeft, Rx_TopRight, Ry_TopRight, Rx_BottomRight, Ry_BottomRight, Rx_BottomLeft, Ry_BottomLeft)))"
i path lable as v
what is wrong
 

drgottjr

Expert
Licensed User
Longtime User
the method exits in RadientDrawable, but not in ColorDrawable
 
Upvote 0

yaniv hanya

Active Member
Licensed User
What is the difference between the apps.
What exactly do you transmit as the v parameter?
These are two versions of the same app writing in one I passed a panel and one I passed a label

the method exits in RadientDrawable, but not in ColorDrawable
You're probably right. And that's probably the problem.
The times it worked the controls were set in the designer and then their background is both ColorDrawable and also RadientDrawable
And when I created the control at runtime his background was just ColorDrawable . Probably that's why it crashed.
Is there a way to create a control at runtime whose background will be also RadientDrawable
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
When you add the Label in the code you need to set the background color with this:
B4X:
Private cdw As ColorDrawable
cdw.Initialize(Colors.White, 0)
Label2.Background = cdw
Then, setCornerRadii works.

If you set the background color only with this:
B4X:
Label2.Color = Colors.White
it doesn't work.
 
Last edited:
Upvote 0

yaniv hanya

Active Member
Licensed User
By the way klaus, the Sub "setCornerRadii" isyour code that I took from here .
So you might need to update it if it no longer supports ColorDrawable.
Anyway thank you so much now everything works well
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I wasn't aware that "setCornerRadii" doesn't work with only Label2.Color = Colors, before seeing your thread.
I knew that it worked with Labels added in the Designer.
Therefore I tested it like you and saw that there was a problem.
Then I remembered that ColorDrawable.Initialize has a Radius parameter so I tested it and it worked.

I added a note in the code snippet thread.
 
Upvote 0
Top