Android dialog box

Source: Internet
Author: User

Android Message notification dialog box:

1) toast. maketext (login. This, R. String. login_dialog_note, Toast. length_long). Show ();

2) custom

Public void showtoast (){
Layoutinflater li = (layoutinflater) getsystemservice (context. layout_inflater_service );
View view = Li. Inflate (R. layout. Toast, null );
// Convert the layout file toast. xml into a view
Toast = new toast (this );
Toast. setview (View );
// Load the view to display the content of toast. xml.
Textview TV = (textview) view. findviewbyid (R. Id. TV1 );
TV. settext ("Toast show View content ");
// Modify the content in textview
Toast. setduration (toast. length_short );
// Set the display time, which is toast. length_long for a long time and toast. length_short for a short time. You cannot edit it by yourself.
Toast. Show ();
}

 

The content of toast. XML is as follows:

<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<Imageview Android: src = "@ drawable/toast"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
/>
<Textview Android: Id = "@ + ID/TV1"
Android: text = ""
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
/>
</Linearlayout>

 

Android selection dialog box:

New alertdialog. Builder (dialogdemo. This)
. Seticon (R. drawable. icon32)
. Settitle (R. String. alert_dialog_two_buttons_msg)
. Setmessage (R. String. alert_dialog_two_buttons3_msg)
. Setpositivebutton (R. String. alert_dialog_yes,
New dialoginterface. onclicklistener (){
Public void onclick (dialoginterface dialog,
Int whichbutton ){

/* User clicked OK so do some stuff */
}
})
. Setnegativebutton (R. String. alert_dialog_no,
New dialoginterface. onclicklistener (){
Public void onclick (dialoginterface dialog,
Int whichbutton ){

/* User clicked OK so do some stuff */
}
})
. Create ();

Seticon uses the icon, settitle () sets the title, setmessage () sets the content of the displayed dialog box, setpositivebutton sets the first button, and the first attribute is the content of the set button, the second attribute is to set the event after clicking. setnegativebutton sets the second button as the first button.

Related Article

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.