Toast prompt for Android development with images

Source: Internet
Author: User

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

Related Article

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.