zoukankan      html  css  js  c++  java
  • 关于Toast的小练习

    第一次编写的失误:不知道如何处理图片。首先是new view 然后new imageview ,再通过一个linearation 将两个view添加,最后toast将linearation添加到view

    package com.android.test;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.Gravity;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.LinearLayout;
    import android.widget.Toast;


    public class ToastActivity extends Activity {
     private Button button1,button2;
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            button1=(Button)findViewById(R.id.bn1);
            button2=(Button)findViewById(R.id.bn2);
            button1.setText("按钮一");
            button2.setText("按钮二");
            button1.setOnClickListener(new OnClickListener() {
       
       @Override
       public void onClick(View v) {
        // TODO Auto-generated method stub
       Toast.makeText(ToastActivity.this, "测1试,加油哦亲", 1000).show();
       
       }
      });
           
            button2.setOnClickListener(new OnClickListener() {
       
       @Override
       public void onClick(View v) {
        // TODO Auto-generated method stub

         Toast toast =Toast.makeText(ToastActivity.this, "ceshi", 1000);
       toast.setGravity(Gravity.CENTER, 0, 0);
       View view = toast.getView();
       ImageView imageView = new ImageView(ToastActivity.this);
       imageView.setImageResource(R.drawable.a);
       LinearLayout layout =new LinearLayout(ToastActivity.this);
       layout.addView(imageView);
       layout.addView(view);
           toast.setView(layout);
           toast.show();
       
           
       
       }
      });
           
           
        }
       
    }

  • 相关阅读:
    Servlet三种实现方法(四)
    Tomcat 网站部署(三)
    MySQL表的增删改查和列的修改(二)
    Tomcat的目录结构(二)
    addEventListener,attachEvent
    DOM事件流
    函数内部的函数中的this都是指向window
    css3 translate属性
    parent,parents和closest
    each用法
  • 原文地址:https://www.cnblogs.com/benxiong/p/2973303.html
Copyright © 2011-2022 走看看