android-dialog box

Source: Internet
Author: User

Three kinds: Dialog, Dialog theme activities, Toast

Dialog(Alert)

Dialog d =NewDialog (myactivity. This); //use a new window to colorize the window it obscures and blur itwindow window =D.getwindow ();                Window.setflags (WindowManager.LayoutParams.FLAG_BLUR_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND); //Set TitleD.settitle ("Dialog Title"); //Expand LayoutsD.setcontentview (R.layout.dialog_view); //find the TextView used in the layout and set its text valueTextView Text =(TextView) D.findviewbyid (R.id.dialogtextview); Text.settext ("This was the text in my dialog");
D.show ();
Alertdialog.builder AD =NewAlertdialog.builder (context); Ad.settitle ("Title"); Ad.setmessage ("Message"); Ad.setpositivebutton ("Button1",NewOnclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich)        {                            }        }); Ad.setnegativebutton ("Button2",NewOnclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich)        {                            }        }); Ad.setcancelable (true); Ad.setoncancellistener (NewOncancellistener () {@Override Public voidonCancel (Dialoginterface dialog) {}}) ; Ad.show ();

Dialog Themed Events

<activity android:name= "mydialogactivity" Android:theme= "@android: Style/theme.dialog" ></activity>

Toast

Toast.maketext (This, String.Format ("name%s, gender%s, age%d", Data.getusername (), Data.getsex (), Data.getage ()), Toast.length_short). Show ();

Management of dialog boxes

The Oncreatedialog and Onpreparedialog event handlers in the activity can save and manage dialog boxes. After you create a dialog box for the first time in Oncreatedialog, each call to ShowDialog triggers Onpreparedialog, where you can modify the value you want to display

    Static Final Private intTime_dialog = 1; @OverrideprotectedDialog Oncreatedialog (intID) {Switch(ID) { Case(time_dialog): Alertdialog.builder timedialog=NewAlertdialog.builder ( This); Timedialog.settitle ("Titile"); Timedialog.setmessage ("Message"); returntimedialog.create (); }        return NULL; } @Overrideprotected voidOnpreparedialog (intID, Dialog Dialog) {        Switch(ID) { Case(time_dialog): Alertdialog timedialog=(alertdialog) dialog; Timedialog.setmessage ("New Message");  Break; }} showDialog (Time_dialog);

android-dialog box

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.