zoukankan      html  css  js  c++  java
  • Toast 显示一个ImageView,Toast 显示一个Button,Toast 显示一个TextView

    一: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 }
  • 相关阅读:
    pytorch bug: for step,data in enumerate(loader)+Connection reset by peer
    pytorch bug
    ImportError: No module named '_tkinter', please install the python3-tk package
    nvidia-docker+cuda8.0+ubuntu16.04
    召回率,精确率,mAP如何计算
    tensorflow 迭代周期长,每个epoch时间变慢
    yolov3中 预测的bbox如何从特征图映射到原图?
    知乎问题:目标检测领域还有什么可以做的?
    目标检测数据增强,旋转方法
    OpenBLAS(1)----安装OpenBLAS
  • 原文地址:https://www.cnblogs.com/xiaoli3007/p/3891828.html
Copyright © 2011-2022 走看看