How to create custom popup
from the CommonsWare Community archivesAt September 27, 2019, 9:11am, Pvr asked:
How a custom popup is created in android along with some actions(Buttons,input from user…) in that
which is prefered between AlertDialog and DialogFragment for that
At September 27, 2019, 10:54am, mmurphy replied:
Usually, you want your dialog to remain visible across configuration changes (screen rotate, locale change, entering/exiting split-screen mode, enabling/disabling Android 10’s dark mode, etc.). One way to do that is via DialogFragment
.
With DialogFragment
, you have your choice of supplying the whole Dialog
(e.g., using AlertDialog
) or just providing the core UI.
I have a chapter on dialogs in The Busy Coder’s Guide to Android Development.
At October 6, 2019, 9:29am, Pvr replied:
ok
I also want to know about Toast Popup and Message Popup
creation
At October 6, 2019, 10:32am, mmurphy replied:
Sorry, but I do not know what “Message Popup” means.
To show a Toast
, call Toast.makeText(context, ..., Toast.LENGTH_LONG).show()
, where context
is a Context
(such as your Activity
) and ...
is a string or string resource ID. You can also use Toast.LENGTH_SHORT
instead of Toast.LENGTH_LONG
for a shorter-duration message.
At October 6, 2019, 10:57am, Pvr replied:
I want to give Layout for the toast (Dialog as a Toast )
At October 6, 2019, 11:32am, mmurphy replied:
You would use something like:
Toast toast = new Toast();
toast.setView(...);
toast.setDuration(Toast.LENGTH_LONG);
toast.show();
where ...
is your View
. Personally, I do not recall ever using this approach.
Bear in mind that a Toast
is non-interactive, so you will not be able to have input widgets (EditText
, Button
, etc.) that work.
At October 19, 2019, 8:03am, Pvr replied:
Is it possible to place Dialog where i want by providing (X,Y,width,height)
At October 19, 2019, 11:04am, mmurphy replied:
I have never done that, but apparently you can manipulate the LayoutParams
for the window to do that.
At October 19, 2019, 12:15pm, Pvr replied:
It is not working, Is it Correct way or any other way
At October 19, 2019, 12:32pm, mmurphy replied:
I have no idea. As I stated, I have never done this.