关于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();
   
       
   
   }
  });
       
       
    }
   
}

posted @ 2013-03-21 14:02  kanrun  阅读(142)  评论(0编辑  收藏  举报