Android Question Panel As Dialog

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi, i need to have a custom dialog.
I tried the Dialog library loaded with a layout (with a panel), but the dialog has the black borders.

417285978-min.jpg

If there is a way to remove the background color from this dialog, i think it's good, but if it's not possilble to do this, i need something that esthetically looks like a panel in front of everything
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
Hi, i need to have a custom dialog.
I tried the Dialog library loaded with a layout (with a panel), but the dialog has the black borders.

View attachment 80767

If there is a way to remove the background color from this dialog, i think it's good, but if it's not possilble to do this, i need something that esthetically looks like a panel in front of everything
The image is not well is too small, post an image if possible larger.:D

Anyway it is more useful to see the code you use to give you some suggestions
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
The image is not well is too small, post an image if possible larger.:D
Sorry, it's a screenshot :D i should have resize it somehow :confused:

Anyway it is more useful to see the code you use to give you some suggestions
B4X:
Dim cd As CustomLayoutDialog

...

Sub btnImpostaLuogoAUTO_Click
    ShowGP
End Sub

...

Sub ShowGP
    cd.ShowAsync("", "", "", "", Null, True)
    cd.SetSize(100%x, 100%y)
    
    Wait For Dialog_Ready (DialogPanel As Panel)
    DialogPanel.LoadLayout("GooglePLaces")
    
    DialogPanel.Color = Colors.ARGB(0,0,0,0)
End Sub

It's technically the same code used in the example of the library:
https://www.b4x.com/android/forum/threads/customlayoutdialog-with-customlistview.82259/#content
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
Check B4XDialog. It is made of a panel with all kinds of features. You can customize it in many ways.
I think i already tested in the past that object, but if i'm not wrong the problem was that it doesn't shows in front of everything, anyway I will take another look now
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
It will show above all other views unless you added a panel with an elevation higher than 4dip (in that case you can easily change the dialog elevation).


Ok Done! it's perfect i used the B4XDialog, the problem is that when i use the Backbutton it doesn't close the dialog but close the activity :(
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
You have to intercept the BACK key in the activity
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
You have to intercept the BACK key in the activity
i tried, it closes anyway

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
    If ((KeyCode = 269) Or (KeyCode = KeyCodes.KEYCODE_BACK)) And (pnlDialog.Tag == False) Then
        HandleBackKey
    Else If (pnlDialog.Tag == True) Then
        btnOkDialog_Click
        Return False
    Else
        Return True
    End If
End Sub

I saved in the pnlDialog.Tag if the dialog is shown or not (if false is it not shown, if true yes)
then in btnCloseDialog_Click i have:

B4X:
Sub btnOkDialog_Click
    dialog.Close(DialogResponse.POSITIVE)
    pnlDialog.Tag = False
End Sub

Edit: Before you ask, the sub "HandleBackKey" works properly (it show a classic MsgBoxAsync, if i hit "No" or "Cancel" it doensn't go back), the problem is only with the B4XDialogs
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
    If ((KeyCode = 269) Or (KeyCode = KeyCodes.KEYCODE_BACK)) And (pnlDialog.Tag == False) Then
        HandleBackKey
        Return True  '<-------------------------------
    Else If (pnlDialog.Tag == True) Then
        btnOkDialog_Click
        Return False
    Else
        Return True
    End If
End Sub
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
    If ((KeyCode = 269) Or (KeyCode = KeyCodes.KEYCODE_BACK)) And (pnlDialog.Tag == False) Then
        HandleBackKey
        Return True  '<-------------------------------
    Else If (pnlDialog.Tag == True) Then
        btnOkDialog_Click
        Return False
    Else
        Return True
    End If
End Sub

ohu, ok better, but now if the dialog is show and i press the backbutton it closes and then it runs the HandleBacKey sub immediatly

Like it pass through the KeyPress event two time, the first closes the dialog (so the tag now is False) and then it pass to the first condition
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
do something like that, now I can't write you the exact code because I have something else on my hands that I can't leave
B4X:
If DialogIsOpen=False then HandleBackKey
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
do something like that, now I can't write you the exact code because I have something else on my hands that I can't leave
B4X:
If DialogIsOpen=False then HandleBackKey

yes, this is the functionality of this if:

B4X:
 If ((KeyCode = 269) Or (KeyCode = KeyCodes.KEYCODE_BACK)) And (pnlDialog.Tag == False) Then
        HandleBackKey

but it fails
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Try it
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
    If ((KeyCode = 269) Or (KeyCode = KeyCodes.KEYCODE_BACK)) Then
        If (pnlDialog.Tag == False) then  
             ' Dialog is Close - Close Activity
             Activity.close
        Else
             ' Dialog is Open - Close Dialog
             btnOkDialog_Click
        End If
        Return True
    Else
        Return False
    End If
End Sub

If the BACK button is intercepted several times, then put a sleep (300) before closing the dialog box.
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
Try it
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
    If ((KeyCode = 269) Or (KeyCode = KeyCodes.KEYCODE_BACK)) Then
        If (pnlDialog.Tag == False) then 
             ' Dialog is Close - Close Activity
             Activity.close
        Else
             ' Dialog is Open - Close Dialog
             btnOkDialog_Click
        End If
        Return True
    Else
        Return False
    End If
End Sub

If the BACK button is intercepted several times, then put a sleep (300) before closing the dialog box.

It's not allowed to put Sleep and Wait For in Activity_KeyPress
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
there are other methods ... cmq now you have to do it alone
 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Try this
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        If dialog.Close(xui.DialogResponse_Cancel) Then Return True
    End If
    Return False
End Sub
 
Upvote 0
Top