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

Discussion in 'Additional libraries, classes and official updates' started by Erel, Nov 26, 2018.

Thread Status:
Not open for further replies.
  1. Erel

    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):
    Code:
    Sub ShowDialog
       
    Dim p As B4XView = xui.CreatePanel("")
       p.SetLayoutAnimated(
    000300dip170dip'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:
    Code:
    '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:
    Code:
    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: Jan 1, 2019
    paragkini, Levit, naifnas and 16 others like this.
  2. Erel

    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: Nov 29, 2018
    JakeBullet70 and inakigarm like this.
  3. fbritop

    fbritop Active Member Licensed User

    Do you have a running example in B4I?
    Thanks
    FBP
     
  4. OliverA

    OliverA Well-Known Member Licensed User

    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.
     
    Erel likes this.
  5. Erel

    Erel Administrator Staff Member Licensed User

Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice