Android study note 36: Message tip

Source: Internet
Author: User

In Android, if the program prompts a small amount of messages and you do not need to perform any operations, you can use the lightweight message toast provided by Android.

Text prompt.

Message prompts with images


Use a toast instance.

Public class toasttest extends activity {@ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); button simple = (button) findviewbyid (R. id. simple); // bind the event listener simple to the Click Event of the button. setonclicklistener (New onclicklistener () {@ overridepublic void onclick (View Source) {// create a toast prompt message Toast = toast. maketext (toasttest. this, "simple prompt information" // sets the toast message duration, toast. length_short); toast. show () ;}}); button bn = (button) findviewbyid (R. id. BN); // bind event listener bn to the Click Event of the button. setonclicklistener (New onclicklistener () {@ overridepublic void onclick (View Source) {// create a toast prompt message Toast = toast. maketext (toasttest. this, "prompt information with image" // sets the toast message duration, toast. length_long); toast. setgravity (gravity. center, 0, 0); // obtain the original viewview toastview = toast in the toast prompt. getview (); // create an imageviewimageview image = new imageview (toasttest. this); image. setimageresource (R. drawable. tools); // create a linearlayout container linearlayout LL = new linearlayout (toasttest. this); // Add images and original viewll to linearlayout. addview (image); LL. addview (toastview); toast. setview (LL); toast. show ();}});}}

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.