1. Toast Usage
Toast can be set: Time, location, custom view
1.1 Most common toast
Toast.maketext (toastactivity. this, "Carloz short Toast", Toast.length_short). Show ();
1.2 Changing the display location of toast
Toast shorttoast = Toast.maketext (toastactivity. this, the "Carloz short Toast"// display position on the screen shorttoast.show ();
1.3 Displaying a custom view
Toast imgtoast = Toast.maketext (toastactivity. This, "Carloz Image Toast", Toast.length_short); ImageView IV=NewImageView (toastactivity. This); Iv.setimageresource (R.drawable.ic_launcher); TextView TV=NewTextView (toastactivity. This); Tv.settext ("Carloz Image Toast"); Tv.setlayoutparams (Newlayoutparams (layoutparams.match_parent, layoutparams.wrap_content)); LinearLayout ll=NewLinearLayout (toastactivity. This); ll.setorientation (linearlayout.vertical); Ll.addview (TV); Ll.addview (iv) ;//Imgtoast.setview (iv);//picture instead of text, if you want to display multiple elements, to customize layout, which contains multiple elementsImgtoast.setview (ll); Imgtoast.show ();
The effect is as follows
2. Notification use
Android Toast and notification