android Toast 消息提示 例子

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

ch7_toast.xml:



    
    

ToastActivity.java:

package com.example.ch7;

import com.example.baseexample.R;

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

public class ToastActivity extends Activity {

	private Button bt_showToast;
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch7_toast);
		
		bt_showToast = (Button)findViewById(R.id.bt_showToast);
		bt_showToast.setOnClickListener(new Button.OnClickListener(){

			@Override
			public void onClick(View arg0) {
				Toast toast = Toast.makeText(ToastActivity.this, "这是一个带图片的Toast", Toast.LENGTH_LONG);
				LinearLayout toastView = (LinearLayout)toast.getView();
				ImageView imageView = new ImageView(ToastActivity.this);
				imageView.setImageResource(R.drawable.a);
				toastView.addView(imageView);
				toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
				toast.show();
				
			}
			
		});
	}
}


转载于:https://my.oschina.net/u/2552902/blog/543955

你可能感兴趣的:(android Toast 消息提示 例子)