标签:android style blog color os io ar cti
一:Toast 显示一个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 /*设置主屏布局*/ 12 setContentView(R.layout.main); 13 /*创建新Toast对象*/ 14 Toast showImageToast=new Toast(this); 15 /*创建新ImageView对象*/ 16 ImageView imageView=new ImageView(this); 17 /*从资源中获取图片*/ 18 imageView.setImageResource(R.drawable.argon); 19 /*设置Toast上的View--(ImageView)*/ 20 showImageToast.setView(imageView); 21 /*设置Toast显示时间*/ 22 showImageToast.setDuration(Toast.LENGTH_LONG); 23 /*显示Toast*/ 24 showImageToast.show(); 25 } 26 }
二:Toast 显示一个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 @Override 10 public void onCreate(Bundle savedInstanceState) { 11 super.onCreate(savedInstanceState); 12 /* 设置主屏布局*/ 13 setContentView(R.layout.main); 14 /* 创建新Toast对象*/ 15 Toast showImageToast = new Toast(this); 16 // /*新建Button对象*/ 17 Button button = new Button(this); 18 button.setText("OK"); 19 /* 设置Toast上的View--(Button) */ 20 showImageToast.setView(button); 21 /* 设置Toast显示时间*/ 22 showImageToast.setDuration(Toast.LENGTH_LONG); 23 /* 显示Toast */ 24 showImageToast.show(); 25 } 26 }
三:Toast 显示一个TextView
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 /* 设置主屏布局*/ 12 setContentView(R.layout.main); 13 /* 创建新Toast对象*/ 14 Toast showImageToast = new Toast(this); 15 /*新建TextView对象*/ 16 TextView text=new TextView(this); 17 /*设置TextView内容*/ 18 text.setText("显示在Toast中的TextView"); 19 /* 设置Toast上的View--(TextView) */ 20 showImageToast.setView(text); 21 /* 设置Toast显示时间*/ 22 showImageToast.setDuration(Toast.LENGTH_LONG); 23 /* 显示Toast */ 24 showImageToast.show(); 25 } 26 }
Toast 显示一个ImageView,Toast 显示一个Button,Toast 显示一个TextView,布布扣,bubuko.com
Toast 显示一个ImageView,Toast 显示一个Button,Toast 显示一个TextView
标签:android style blog color os io ar cti
原文地址:http://www.cnblogs.com/xiaoli3007/p/3891828.html