As we all know, toast is an information reminder tool that does not affect normal use of users. However, by default, toast can only display text. Is it a bit single? Can it display toast with images.
Don't worry. The answer is yes. Show it.
Private Void Showtoast (){ // 1 create toast Toast = toast. maketext ( This ," Graphic Display, not a bit ^_^ ", Toast. length_long ); // 2 create layout and set it to horizontal layout Linearlayout mlayout = New Linearlayout ( This ); Mlayout. setorientation (linearlayout. Horizontal); imageview mimage = New Imageview (This ); // Display the imageview of the image Mimage. setimageresource (R. drawable. Icon); view toastview = toast. getview (); // Obtain the toast view of the displayed text Mlayout. addview (mimage ); // Add to layout Mlayout. addview (toastview ); // 3. Set the view displayed by toast (layout generated above ). Toast. setview (mlayout); toast. Show ();}
Is it a bit simple? It's just a simple linearlayout. Can you display a more complex view ......
In addition to allowing toast to display images, we can also change the default position of toast:
Toast. setgravity (gravity, xoffset, yoffset );
OK. The toast extension is available here today ~
Welcome to exchange and study