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.