Zhao Yazhi _android_ui_dialog

Source: Internet
Author: User

Operating effect:
Method One

public void OpenDialog (View v) {//Opens a dialog//builder object Alertdialog.builder Builder = new Builder (this);//The Builder creates a dialog box Alertdialo G Alertdialog = Builder.create ();//The caption of the settings dialog alertdialog.settitle ("I am the dialog box");//Settings dialog box Contents Alertdialog.setmessage (" Do you really want to quit the program? ");//Settings Dialog Icon Alertdialog.seticon (r.drawable.ic_launcher); Alertdialog.setbutton (dialoginterface.button_positive , "OK", new Onclicklistener () {@Overridepublic void OnClick (dialoginterface dialog, int which) {//TODO auto-generated Meth Od stubtoast.maketext (mainactivity.this, "OK", Toast.length_long). Show ();}); Alertdialog.setbutton (dialoginterface.button_neutral, "neutral", new Onclicklistener () {@Overridepublic void OnClick ( Dialoginterface dialog, int which) {Toast.maketext (mainactivity.this, "neutral", Toast.length_long). Show ();}); Alertdialog.setbutton (Dialoginterface.button_negative, "Cancel", new Onclicklistener () {@Overridepublic void OnClick ( Dialoginterface dialog, int which) {Toast.maketext (Mainactivity.this, "Cancel", Toast.length_long). Show ();}); /Alertdialog must be set.Show ();} 

Method 2
public void OpenDialog (View v) {new Alertdialog.builder (this). Settitle ("I am a dialog box"). Setmessage ("Do you really want to quit the program"). SetIcon ( R.drawable.ic_launcher). Setpositivebutton ("OK", new Onclicklistener () {@Overridepublic void OnClick (dialoginterface dialog, int which) {//TODO auto-generated method Stubtoast.maketext (mainactivity.this, "OK", Toast.length_long). Show () ;}}). Setneutralbutton ("neutral", new Onclicklistener () {@Overridepublic void OnClick (dialoginterface dialog, int which) { Toast.maketext (Mainactivity.this, "neutral", Toast.length_long). Show ();}}). Setnegativebutton ("Cancel", new Onclicklistener () {@Overridepublic void OnClick (dialoginterface dialog, int which) { Toast.maketext (Mainactivity.this, "Cancel", Toast.length_long). Show ();}}). Create (). Show (); }

Method 3 Create a new activity, set the theme theme in Androidmenifest.xmlandroid:theme= "@android: Style/theme.dialog"


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.