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