Recently available, to the app used in the dialog dialog box to write a blog, in the app many places will use the dialog dialog box, today, I will introduce you to Dialog dialog box.
First Look at:
12 kinds, according to the needs of the choice, the bottom of the frame can also be achieved through the Dialog dialog box, you can not popupwindow to achieve, more convenient
Android Support Library v22.1 is beginning to provide Material-style Dialog controls that look nice too
Material-Style dialog class: Android.support.v7.app.AlertDialog
The Alertdialog in this V7 package can provide compatibility Material style over Android 2.1 Dialog
To illustrate:
Public StaticAlertdialog.builder Getmessagedialog (context context, String message, Dialoginterface.onclicklistener Onclicklistener) {Alertdialog.builder Builder=Getdialog (context); Builder.settitle ("I am the title"); Builder.setmessage (message);/*Message Content*/Builder.seticon (r.mipmap.ic_launcher);/*logo icon*/Builder.setpositivebutton ("OK", onclicklistener);/*Determining event Snooping*/Builder.setnegativebutton ("Cancel",NULL);/*Cancel event (can listen or not listen (close window))*/ returnBuilder; }
Using the call
Dialoghelper.getmessagedialog (Thisnew Dialoginterface.onclicklistener () { @Override Public void int which) { Toast.maketext (mainactivity). This, "Basic dialog box, and listen OK button", Toast.length_long). Show (); } }). Show ();
Effect
Progress Bar dialog box
/** * * Get a progress dialog box (time consuming operation) * *
@param
context *
@param
message loading hint information *
@return
*/
public
static
ProgressDialog Getwaitdialog (context context, String message) {ProgressDialog Waitdialog =
new
ProgressDialog (context);
if (!
return Waitdialog; }
Informational and listener OK and Cancel buttons only, select dialog box
single-selection dialogs and custom dialogs (sometimes the various methods that are brought to our dialog do not meet our design needs, we can write our own XML design to meet the needs of the dialog. (Only the message part of the design dialog, not the dialog overall))
/*** * Single-Select dialog box *@paramContext *@paramTitle *@paramArrays Array Information *@paramSelectindex selected by default *@paramOnclicklistener radio Button Select event *@paramOnokclicklistener Determining button Events *@return */ Public StaticAlertdialog.builder Getsinglechoicedialog (Context context, String title, string[] arrays,intSelectindex, Dialoginterface.onclicklistener Onclicklistener, Dialoginterface.onclicklistener Onokclicklistener) {Alertdialog.builder Builder=Getdialog (context); Builder.setsinglechoiceitems (arrays, Selectindex, Onclicklistener); if(!Textutils.isempty (title)) {Builder.settitle (title); } Builder.setpositivebutton (Determine, Onokclicklistener); Builder.setnegativebutton ("Cancel",NULL);//null=== Close dialog box returnBuilder; }
/*** * Customize dialog box*/Layoutinflater Inflater=Getlayoutinflater (); View Dialog=inflater.inflate (R.layout.dialog_normal_layout, (ViewGroup) Findviewbyid (R.id.dialog)); FinalEditText EditText =(EditText) Dialog.findviewbyid (r.id.et); Alertdialog.builder Builder1=NewAlertdialog.builder ( This); Builder1.settitle ("This is the title"); Builder1.setpositivebutton ("OK",NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {Toast.maketext (mainactivity). This, Edittext.gettext (). toString (), Toast.length_short). Show (); } }); Builder1.setnegativebutton ("Cancel",NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {Toast.maketext (mainactivity). This, "Cancel", Toast.length_short). Show (); } }); Builder1.setview (Dialog); Builder1.seticon (R.mipmap.ic_launcher); Builder1.show ();
Apps often need the following pop-up windows, rounded corners, almost all iOS, the bottom dialog box (photo selection or sharing),
Both of these methods require a custom Dialog class to implement this functionality, and you can use the Android.app.Dialog class to Create class inheritance Dialog.
Because of the code too much, do not paste it out, direct download can, do not point Oh!
Please leave a comment on the shortcomings. If you have any questions, please leave me a message! Thank you!
Android ui--Create 12 Dialog dialog boxes