LucaMs Expert Licensed User Longtime User Feb 5, 2018 #1 I tried to use other methods in the code snippet "Custom Toast Message". 1: Code: Copy ' Seems to not work. Dim horizontalMargin, verticalMargin As Float horizontalMargin = 50 '% verticalMargin = 25 ' % toast.RunMethod("setMargin", Array (horizontalMargin, verticalMargin)) 2: Code: Copy Dim pnl As Panel ... toast.RunMethod("setView", pnl) ' incompatible types: ViewGroup cannot be converted to Object[] ' Error even if I use a simple Label. Also, is there a way to increase the size of the toast? [I used this and it is useful enough: cs.Initialize.Color(Colors.Blue).Size(50).Append("Custom" & CRLF & CRLF & "Toast").PopAll (I know, I should use smart strings in my code ) ]
I tried to use other methods in the code snippet "Custom Toast Message". 1: Code: Copy ' Seems to not work. Dim horizontalMargin, verticalMargin As Float horizontalMargin = 50 '% verticalMargin = 25 ' % toast.RunMethod("setMargin", Array (horizontalMargin, verticalMargin)) 2: Code: Copy Dim pnl As Panel ... toast.RunMethod("setView", pnl) ' incompatible types: ViewGroup cannot be converted to Object[] ' Error even if I use a simple Label. Also, is there a way to increase the size of the toast? [I used this and it is useful enough: cs.Initialize.Color(Colors.Blue).Size(50).Append("Custom" & CRLF & CRLF & "Toast").PopAll (I know, I should use smart strings in my code ) ]
Erel B4X founder Staff member Licensed User Longtime User Feb 5, 2018 #2 Where does this code come from? Which error did you get? The toast message should be large enough to hold the content. It grows automatically. Upvote 0
Where does this code come from? Which error did you get? The toast message should be large enough to hold the content. It grows automatically.
LucaMs Expert Licensed User Longtime User Feb 5, 2018 #3 Erel said: Where does this code come from? Click to expand... https://developer.android.com/reference/android/widget/Toast.html#setMargin(float, float) https://developer.android.com/reference/android/widget/Toast.html#setView(android.view.View) Erel said: Which error did you get? Click to expand... 1. No errors - I thought to be able to change the toast position using that method. 2. That method requires a View (Java) as parameter; is not a b4a Label an Android Java View? Upvote 0
Erel said: Where does this code come from? Click to expand... https://developer.android.com/reference/android/widget/Toast.html#setMargin(float, float) https://developer.android.com/reference/android/widget/Toast.html#setView(android.view.View) Erel said: Which error did you get? Click to expand... 1. No errors - I thought to be able to change the toast position using that method. 2. That method requires a View (Java) as parameter; is not a b4a Label an Android Java View?
Erel B4X founder Staff member Licensed User Longtime User Feb 5, 2018 #4 1. The code is correct, though it is missing dip units. If it doesn't work then this method doesn't do what you want it to do. You can call setGravity as in the commented code: https://www.b4x.com/android/forum/threads/custom-toast-message.89173/ 2. It should be Array(pnl) Upvote 0
1. The code is correct, though it is missing dip units. If it doesn't work then this method doesn't do what you want it to do. You can call setGravity as in the commented code: https://www.b4x.com/android/forum/threads/custom-toast-message.89173/ 2. It should be Array(pnl)
LucaMs Expert Licensed User Longtime User Feb 5, 2018 #5 Erel said: though it is missing dip units. Click to expand... "horizontalMargin float: The horizontal margin, in percentage of the container width," Erel said: If it doesn't work then this method doesn't do what you want it to do. Click to expand... Almost certainly; who knows what his purpose is, then Erel said: 2. It should be Array(pnl) Click to expand... Spoiler: Error msg java.lang.IllegalArgumentException: View=anywheresoftware.b4a.BALayout{21ea0ea8 V.E..... ......I. 0,0-225,210 #3} not attached to window manager at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:370) at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:299) at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:79) at android.widget.Toast$TN.handleShow(Toast.java:402) at android.widget.Toast$TN$1.run(Toast.java:313) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:149) at android.app.ActivityThread.main(ActivityThread.java:5257) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610) at dalvik.system.NativeStart.main(Native Method) Could this be due to the initialization mode? Code: Copy Dim toast As JavaObject toast = toast.InitializeStatic("android.widget.Toast").RunMethod("makeText", Array(ctxt, Text, duration)) Upvote 0
Erel said: though it is missing dip units. Click to expand... "horizontalMargin float: The horizontal margin, in percentage of the container width," Erel said: If it doesn't work then this method doesn't do what you want it to do. Click to expand... Almost certainly; who knows what his purpose is, then Erel said: 2. It should be Array(pnl) Click to expand... Spoiler: Error msg java.lang.IllegalArgumentException: View=anywheresoftware.b4a.BALayout{21ea0ea8 V.E..... ......I. 0,0-225,210 #3} not attached to window manager at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:370) at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:299) at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:79) at android.widget.Toast$TN.handleShow(Toast.java:402) at android.widget.Toast$TN$1.run(Toast.java:313) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:149) at android.app.ActivityThread.main(ActivityThread.java:5257) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610) at dalvik.system.NativeStart.main(Native Method) Could this be due to the initialization mode? Code: Copy Dim toast As JavaObject toast = toast.InitializeStatic("android.widget.Toast").RunMethod("makeText", Array(ctxt, Text, duration))
Erel B4X founder Staff member Licensed User Longtime User Feb 5, 2018 #6 2. This is the same case as the other point. setView doesn't do what you expect it to do. Upvote 0