5 Kinds of toast effects on Android

Source: Internet
Author: User

Toast is a mechanism used to display information in Android, unlike dialog, where toast is not focused, and toast is displayed with limited time, and will automatically disappear after a certain amount of time.

1. Default effect:Toast.maketext (Getapplicationcontext (), default Toast style, Toast.length_short). Show (); 2. Custom display position effect: Toast = Toast.maketext (Getapplicationcontext (), "Custom Location Toast", Toast.length_long); Toast.setgravity (gravity.center, 0, 0); Toast.show (); 3. With picture effect: Toast = Toast.maketext (Getapplicationcontext (), "toast with pictures", toast.length_long); Toast.setgravity (gravity.center, 0, 0);  linearlayout toastview = (linearlayout) toast.getview ();  ImageView Imagecodeproject = new ImageView (Getapplicationcontext ()); Imagecodeproject.setimageresource (R.drawable.icon);  toastview.addview (imagecodeproject, 0);  Toast.show (); 4. Fully customizable effect:     layoutinflater Inflater = Getlayoutinflater ();     view layout = Inflater.inflate (R.layout.custom, (ViewGroup) Findviewbyid (r.id.lltoast));   imageview Image = (ImageView) Layout.findviewbyid (r.id.tvimagetoast);     image.setimageresource ( R.drawable.icon)     textview title = (TextView) layout. Findviewbyid (R.id.tvtitletoast);     title.settext ("Attention");     TextView Text = (TextView) Layout.findviewbyid (r.id.tvtexttoast);     text.settext ("Full Custom Toast" );     toast = new Toast (Getapplicationcontext ());     toast.setgravity ( Gravity.right | Gravity.top,     toast.setduration (Toast.length_long);     Toast.setview (layout);     toast.show (); 5. Other Threads: New Thread (new Runnable () { public void run ( {   showtoast ();   }   }). Start ();  Travel Network, A free dating site: www.jieberu.com push-push family, free scenic tickets, scenic spots: www.tuituizu.com

5 Kinds of toast effects on Android

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.