Android杂谈---带图片的Toast

当需要提示的时候,我们可以用Toast来显示信息

如:

Toast t=Toast.makeText(this,"你好",Toast.LENGTH_SHORT);

t.show();

 

那么,如果要想在Toast里面显示图片,该怎么做的,如下,你懂的

package org.hualang.toast;

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

public class ToastTest extends Activity {
    /** Called when the activity is first created. */
	private Button button;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        button=(Button)findViewById(R.id.myid);
        button.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Toast t=new Toast(getApplicationContext());
				ImageView iv=new ImageView(getApplicationContext());
				iv.setImageResource(R.drawable.icon);
				t.setView(iv);
				t.show();
			}
		});
    }
}
 


Android杂谈---带图片的Toast

 

你可能感兴趣的:(android,OS)