Android Question Custom Toast Message - Additional methods

LucaMs

Expert
Licensed User
Longtime User
I tried to use other methods in the code snippet "Custom Toast Message".

1:
B4X:
' Seems to not work.
   Dim horizontalMargin, verticalMargin As Float
   horizontalMargin = 50 '%
   verticalMargin = 25 ' %
   toast.RunMethod("setMargin", Array (horizontalMargin, verticalMargin))


2:
B4X:
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 :D )
]
 

LucaMs

Expert
Licensed User
Longtime User
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
though it is missing dip units.
"horizontalMargin float: The horizontal margin, in percentage of the container width,"
;)

If it doesn't work then this method doesn't do what you want it to do.
Almost certainly; who knows what his purpose is, then :)


2. It should be Array(pnl)
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?
B4X:
    Dim toast As JavaObject
toast = toast.InitializeStatic("android.widget.Toast").RunMethod("makeText", Array(ctxt, Text, duration))
 
Upvote 0
Top