Android Code Snippet Custom Toast Message


Staff member
Licensed User

You can customize the toast message text with CSBuilder:

This code allows you to also change the background color and the toast position:
Sub ShowCustomToast(Text As Object, LongDuration As Boolean, BackgroundColor As Int)
   Dim ctxt As JavaObject
   Dim duration As Int
   If LongDuration Then duration = 1 Else duration = 0
   Dim toast As JavaObject
   toast = toast.InitializeStatic("android.widget.Toast").RunMethod("makeText", Array(ctxt, Text, duration))
   Dim v As View = toast.RunMethod("getView", Null)
  Dim cd As ColorDrawable
  cd.Initialize(BackgroundColor, 20dip)
  v.Background = cd
   'uncomment to show toast in the center:
'   toast.RunMethod("setGravity", Array( _
'       Bit.Or(Gravity.CENTER_HORIZONTAL, Gravity.CENTER_VERTICAL), 0, 0))
   toast.RunMethod("show", Null)
End Sub
Depends on JavaObject library

Usage example:
Sub Activity_Click
   ShowCustomToast("Testing...", True, Colors.Green)
   Dim cs As CSBuilder
   cs.Initialize.Color(Colors.Blue).Size(20).Append("Custom Toast").PopAll
   ShowCustomToast(cs, True, Colors.Red)
End Sub
Last edited:

Walter Brunmueller

Licensed User
I had problems to get a toast message.
Afte hours of testing I found the solution.
It is necessary to activate notification for your app in the android system.

I hope this helps.