Toast displays an imageview, toast displays a button, and toast displays a textview

Source: Internet
Author: User

I. Toast displays an imageview

1 package ZYF. ex_ctrl_3_ B; 2 Import android. app. activity; 3 Import android. OS. bundle; 4 Import android. widget. imageview; 5 import android. widget. toast; 6 public class ex_ctrl_3_ B extends activity {7/** called when the activity is first created. */8 @ override 9 Public void oncreate (bundle savedinstancestate) {10 super. oncreate (savedinstancestate); 11/* set the homepage Layout */12 setcontentview (R. layout. main); 13/* Create a New toast object */14 toast showimagetoast = new toast (this ); 15/* Create a New imageview object */16 imageview = new imageview (this); 17/* retrieve images from resources */18 imageview. setimageresource (R. drawable. argon); 19/* Set View -- (imageview) */20 showimagetoast on toast. setview (imageview); 21/* set the toast display time */22 showimagetoast. setduration (toast. length_long); 23/* display toast */24 showimagetoast. show (); 25} 26}

2. Toast displays a button.

1 package ZYF. ex_ctrl_3_ B; 2 Import android. app. activity; 3 Import android. OS. bundle; 4 Import android. view. view; 5 import android. widget. button; 6 Import android. widget. toast; 7 public class ex_ctrl_3_ B extends activity {8/** called when the activity is first created. */9 @ override10 public void oncreate (bundle savedinstancestate) {11 super. oncreate (savedinstancestate); 12/* set the homepage Layout */13 setcontentview (R. layout. main); 14/* Create a New toast object */15 toast showimagetoast = new toast (this ); 16 // * Create a button object */17 button = new button (this); 18 button. settext ("OK"); 19/* Set View -- (button) */20 showimagetoast on toast. setview (button); 21/* Set toast display time */22 showimagetoast. setduration (toast. length_long); 23/* display toast */24 showimagetoast. show (); 25} 26}

3. display a textview in toast.

1 package ZYF. ex_ctrl_3_ B; 2 Import android. app. activity; 3 Import android. OS. bundle; 4 Import android. widget. textview; 5 import android. widget. toast; 6 public class ex_ctrl_3_ B extends activity {7/** called when the activity is first created. */8 @ override 9 Public void oncreate (bundle savedinstancestate) {10 super. oncreate (savedinstancestate); 11/* set the homepage Layout */12 setcontentview (R. layout. main); 13/* Create a New toast object */14 toast showimagetoast = new toast (this); 15/* Create a textview object */16 textview text = new textview (this ); 17/* Set textview content */18 text. settext ("textview displayed in toast"); 19/* set view on toast -- (textview) */20 showimagetoast. setview (text); 21/* Set toast display time */22 showimagetoast. setduration (toast. length_long); 23/* display toast */24 showimagetoast. show (); 25} 26}

 

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.