B4A Class [B4X] XUI - haB4XMsgBox (based on B4XDialog)


Well-Known Member
Licensed User
Based on @Erel latest B4Xlibs projects, I created this modified class from the B4XDialog source class.
With posted (expertly developed) classes, we can create anything that suits our purpose - without struggling to "get it right". Thanks @Erel - for the lesson on correctness.

The modifications include:
Remove dependency on B4XBitmapCreator (no blur support)
Larger overall box (width adjusted - based on portrait, landscape, tablet, phone)
Larger text font size
Large Buttons with border and background
Buttons stretch to fit box width (with 1, 2, 3 buttons)
Button text is sized accordingly (number of buttons, text.length)
Button color based on return code
Supports up to 4 return codes ( -1 Positive, -2 Negative, -3 Cancel, 0 Abort [Back Button on TitleBar] )
Supports FontAwesome for Title, body and buttons
No Designer Script required (as per original source)

Should work on all three platforms since B4X XUI conditionals remain.
I created it for my needs in B4A and B4i. I use ABMaterial for my B4J needs...

Customize as you wish!

Enjoy. Thanks
(I love classes - and wine glasses...)

Typical Use:

' Activity Globals
Private Dialog As haB4XMsgBox
Private Base As B4XView

' Activity_Create(FirstTime As Boolean)
    Base = Activity
    Dialog.Initialize (Base)

' device (each activity) Back KeyPress handling... Keeps app foreground
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event

    If KeyCode = KeyCodes.KEYCODE_BACK And Dialog.Visible Then
        Dialog.Close(xui.DialogResponse_Cancel) ' ( or return 0 - Abort )
        Return True
    End If
    Return False
End Sub

' button click call...

        Dim msgContent As String = "This is your first chance to opt in for free stuff."&CRLF&CRLF&"( no "&Chr(0xF1F0)&" or "&Chr(0xF1F1)&" required )"&CRLF&CRLF&"Please select your intention."
'        Wait For (Dialog.Show(Chr(0xF0E7)&" Get FREE Stuff!",msgContent,Chr(0xF046),  "","") ) Complete (Result As Int)
'        Wait For (Dialog.Show("Get FREE Stuff "&Chr(0xF0E7),msgContent, Chr(0xF046),  "NO THANKS","") ) Complete (Result As Int)
'        Wait For (Dialog.Show(Chr(0xF0E7)&" Get FREE Stuff!",msgContent,"OK", "","NEVER") ) Complete (Result As Int)
         Wait For (Dialog.Show(Chr(0xF0E7)&" Get FREE Stuff!",msgContent,Chr(0xF046), "PERHAPS LATER", "NO THANKS") ) Complete (Result As Int)

       Log(" Chosen Result: "&Result)


Capture+_2019-01-15-12-02-22 (Medium).png

Capture+_2019-01-15-12-01-44 (Medium).png


Screenshot_20190115-131048 (Medium).jpg

Screenshot_20190115-131120 (Medium).jpg


Last edited:


Staff member
Licensed User
Button color based on return code
Supports FontAwesome for Title, body and buttons
This is also supported by the standard B4XDialog in B4A as it accepts CSBuilder objects for the buttons and title. I will add it to B4i as well.