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:
Code:
Toast.maketext (Getapplicationcontext (), default Toast style, toast.length_short). Show ();
2. Customize the display position effect:
Code:
Toast = Toast.maketext (Getapplicationcontext (), "Custom location Toast", Toast.length_long); 0, 0); Toast.show ();
3. With picture effect:
Code:
Toast = Toast.maketext (Getapplicationcontext (), "toast with pictures", toast.length_long); 0, 0); = (LinearLayout) Toast.getview (); New ImageView (Getapplicationcontext ()); Imagecodeproject.setimageresource (R.drawable.icon); 0); Toast.show ();
4. Fully customizable effects:
Code:
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 ("Fully customizable Toast"); Toast=NewToast (Getapplicationcontext ()); Toast.setgravity (Gravity.right| Gravity.top, 12, 40); Toast.setduration (Toast.length_long); Toast.setview (layout); Toast.show ();
5. Other Threads:
Code:
New Thread (new Runnable () { publicvoid run () { showtoast ()} }). Start ();
Transferred from: http://android.tgbus.com/Android/tutorial/201103/346236.shtml
Android Toast Detailed