Toast display graphic interface-Android Development Path 1, toastandroid

Source: Internet
Author: User

Toast display graphic interface-Android Development Path 1, toastandroid

Multiple Toast usage methods

 

Toast is actually a very powerful component. It can not only have a piece of text on Toast, but also have a mix of Toast pictures and text pages. The usage is as follows:

First: simple plain text-based toast:

Toast. makeText (this, "plain text content", Toast. LENGTH_SHORT). show ();

Type 2: A Toast image:

Toast toast = new Toast (this); ImageView imageView = new ImageView (this); // create an image control imageView. setImageResource (R. mipmap. ic_launcher); // sets the image toast for the control. setView (imageView); // bind the image to Toast. setDuration (Toast. LENGTH_LONG); // display time of Toast; // set the image display position: three parameters // The First One: position, which can be used | Add a parallel position, and the second one: offset relative to X. The third parameter is the offset relative to the Y axis. // note that the second and third parameters are the toast offset relative to the position set by the first parameter. setGravity (Gravity. TOP | Gravity. RIGHT, 0,100); toast. show (); // display Toast

Third Type: text-and-image mixed toast

Toast toast = new Toast (this); LinearLayout linearLayout = new LinearLayout (this); // create a linear layout linearLayout. setOrientation (LinearLayout. VERTICAL); // set the layout VERTICAL ImageView imageView = new ImageView (this); // create an image control imageView. setImageResource (R. mipmap. ic_launcher); // sets TextView textView = new TextView (this) for the control; // creates textView for the text control. setText ("isn't the mythical Prince Handsome?"); // set the text content linearLayout. addView (imageView); // Add the image control to the layout. Ut. addView (textView); // Add a text control to the layout. Note that the order of adding will affect whether the image is in the front or in front of the toast. setView (linearLayout); // bind the layout to Toast. setDuration (Toast. LENGTH_LONG); // display time of Toast; // The parameter is the same as that of toast. setGravity (Gravity. CENTER, 0, 0); toast. show (); // display Toast

Toast also has some other attributes. knowing this is the most basic, and then taking full advantage of our imagination, t can use Toas to create a variety of interface effects.

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.