Android Example [B4X] [XUI] ToastMessage Class Modifications

Based on the work by UDG in the post:

This is a cross platform library that will work in B4a, B4i, and B4j. These modifications help to mimic B4a/B4i ToastMessageShow better.

Modified from the original in the following ways:

1. Length of the toast message panel will now vary with the text width.
2. Made permanent "Center" alignment of text.
3. Changed the font size according to the platform - 14(B4A), 16(B4I), 14(B4J)
4. Change the panel radius according to the platform - 24(B4A), 10(B4I, B4J)
5. Default vertical panel location changed from left to center
6. Allows for moving the panel location using a new command "VerticalOffset"
7. You can now set a min. horizontal panel margin 5-49% of the total screen width using the new command "SetHorizontalMinMargin"

Instructions: Copy the .b4xlib to your additional library location. If you would like to see the code, change the extension to .zip and unzip it.

Warning for B4i applications: You need to either put a small delay before initializing (in "Application_Start") OR put the initialization in the "Sub Page1_Resize". This is so that the layout has enough time to load before calling the initialization.

Example initialization:
Sub Process_Globals
    Private tm As clXToastMessage1
End sub

'Delay method for initialization'
Private Sub Application_Start (Nav As NavigationController)
End Sub

'Resize method for initialization'
Private Sub Page1_Resize(Width As Int, Height As Int)
End Sub



  • clXToastMessage1.b4xlib
    4.1 KB · Views: 196


Licensed User
@gregchao Do you mind providing an example for B4J? Thanks 👍

Here is a B4XPages example. Works with B4J

#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private tm As clXToastMessage1
End Sub

Public Sub Initialize
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    #if B4i
    #End If
    tm.Initialize(B4XPages.MainPage.Root)  'you could shorten to 'Root'
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Sub Button1_Click
    tm.Show("test of toast", True)
End Sub
Last edited:


Licensed User
How is this related to BCToast? Which one should be preferred now for cross-platform usage?

I am not familiar with BCToast. Try them both out. You can easily see and modify my code by changing the extension to .zip and unzip it. After you are done, change the extension back. Erel made it easy to create libraries.