B4A Library [B4X] [XUI] B4XDialog - Custom dialogs

Status
Not open for further replies.

Erel

Administrator
Staff member
Licensed User
Edit: B4XDialogs is part of XUI Views library. Use that instead: [B4X] XUI Views - Cross platform views and dialogs

B4XDialog class helps with creating cross platform custom dialogs. The dialog is made of a simple panel and it is therefore completely customizable.

test.gif

Simple usage (change Activity with MainForm.RootPane or Page1.RootPanel or any other panel you like):
B4X:
Sub ShowDialog
   Dim p As B4XView = xui.CreatePanel("")
   p.SetLayoutAnimated(0, 0, 0, 300dip, 170dip) 'set the content size
   p.LoadLayout("CustomLayout")
   Dim rs As ResumableSub = Dialog.Show(Activity, p, "Ok", "", "Cancel")
   Wait For (rs) Complete (Result As Int)
   If Result = xui.DialogResponse_Positive Then
       'do something
   End If
End Sub
In most cases it requires a bit more work as you also want to handle keyboard changes:
B4X:
'B4A
Sub ime_HeightChanged (NewHeight As Int, OldHeight As Int)
   If Dialog.Visible Then Dialog.Resize(100%x, NewHeight)
End Sub
'B4i
Sub Page1_KeyboardStateChanged (Height As Float)
   If Dialog.Visible Then Dialog.Resize(Page1.RootPanel.Width, Page1.RootPanel.Height - Height)
End Sub
And in B4A you can handle the back key:
B4X:
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)
       Return True
   End If
   Return False
End Sub
The attached B4A example shows how to access the default buttons and change their state based on the forms fields.

B4XDialog class is included in the example.

Dependencies:
- XUI / iXUI / jXUI
- BitmapCreator v4.50+ (copy to the internal library folder if needed)
 
Last edited:

Erel

Administrator
Staff member
Licensed User
V1.10 released with a few changes:

- Blurring of the background. This is an optional feature. It is enabled by default in B4A and B4J and disabled in B4i (the snapshot call is a bit slow in B4i).
- Other small changes.

Tips:

- Don't call AutoScaleAll in the dialog layout. It will not work as expected as the layout is loaded to a smaller panel.
- I encountered issues with FloatLabeledEditText in B4A and the keyboard handling. I recommend using regular EditTexts instead inside the dialog.
- BitmapCreator v4.50+ is required. Link for v4.50 is available above.
 
Last edited:

OliverA

Expert
Licensed User
Do you have a running example in B4I?
Did you follow the link given on the first line (the bold one) of the first post in this thread? The example in that thread (the replacement for this one) includes B4A, B4i and B4J examples.
 
Status
Not open for further replies.
Top