OK Cancel dialog box (with icon)
(context, subject) New Alertdialog.builder (this, alertdialog.theme_device_default_light) . Settitle ("title"). Setmessage (" Content "). SetIcon (R.drawable.ic_launcher)//Respond to click events . Setpositivebutton (" OK ", new Onclicklistener () { @Override Public void OnClick (dialoginterface dialog, int which) { //TODO auto-generated method stub Toast.maketext ( Mainactivity.this, "OK", 0). Show (); } }). Setnegativebutton ("Cancel", null). Show ();//Don't forget Show
Effect
Simple single-selection dialog box
Final string[] strs=new string[]{"male", "female", "Don't Tell You"};new Alertdialog.builder (This, alertdialog.theme_device_default_ Light). Settitle ("title"). SetIcon (R.drawable.ic_launcher)//(string array, default selection, Response event). Setsinglechoiceitems (STRs, 2, new Onclicklistener () {//swich: array of options id@overridepublic void OnClick (dialoginterface dialog, int which) {//TODO Auto-generated method Stubtoast.maketext (Mainactivity.this, Strs[which], 0). Show ();}}). Show ();
Effect
Multi-Select dialog box
Final string[] STRs = new string[] {"Banana", "apple", "pear"}; Alertdialog.builder dialog = new Alertdialog.builder (this, alertdialog.theme_device_default_light). SetTitle (" Title ") . SetIcon (R.drawable.ic_launcher) . Setmultichoiceitems (STRs, New Boolean[]{true,true,false}, new Onmultichoiceclicklistener () { //which: array of selected items id//ischecked: The selected state of the selection @Override the public void OnClick ( Dialoginterface dialog, int which, Boolean isChecked) { //TODO auto-generated method stub log.d ("Test", "which=" +which+ ": ischecked=" +ischecked); } ); Dialog.create (). Show ();
Effect
Progress dialog box
ProgressDialog pd=new ProgressDialog (This);pd. Settitle ("title");pd. Setmessage ("Bring to ...");pd. Show ();
Progress Bar dialog box
Final ProgressDialog pd = new ProgressDialog (this); There are only two themes pd.setprogressstyle (progressdialog.style_horizontal);//Set Maximum progress value Pd.setmax (+); Pd.settitle ("title"); Pd.setmessage ("Please bring to ..."); Pd.show (); New Thread () {public void run () {for (int i = 1; i < i++) { try {Thread.Sleep] } cat CH (interruptedexception e) { //TODO auto-generated catch block e.printstacktrace (); } Pd.setprogress (i); } Can be closed on any thread, Pd.dismiss (); }; }. Start ();
Effect
Customize dialog box
Final EditText et_text = new EditText (this), new Alertdialog.builder (this). Settitle ("Please enter")//Put in a TextView . SetIcon (Android. R.drawable.ic_dialog_info). Setview (Et_text) . Setpositivebutton ("OK", new Onclicklistener () { @Override Public void OnClick (dialoginterface dialog, int which) { //TODO auto-generated method stub Toast.maketext ( Mainactivity.this, Et_text.gettext (). toString (), 0). Show (); } }). Setnegativebutton ("Cancel", null). Show ();
Effect
Customizing the Layout dialog boxLayout File
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "/http Schemas.android.com/apk/res/android "android:layout_width=" match_parent "android:layout_height=" Match_parent "and roid:orientation= "vertical" > <textview android:layout_width= "match_parent" android:layout_height= " Wrap_content "android:text="??? Summary notes for various Android dialog boxes