Toast内容显示图
- package com.smart;
- import android.app.Activity;
- import android.content.DialogInterface;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.TextView;
- import android.widget.Toast;
- public class Main extends Activity implements OnClickListener{
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);//得到参数
- Button btnTextToast = (Button) findViewById(R.id.btnTextToast);
- Button btnImageToast = (Button) findViewById(R.id.btnImageToast);
- btnTextToast.setOnClickListener(this);//绑定器
- btnImageToast.setOnClickListener(this);
- }
- //点击方法事件
- @Override
- public void onClick(View v) {
- switch(v.getId()){
- case R.id.btnTextToast:
- //使用TOAST方法显示结果内容
- Toast textToast=Toast.makeText(this, "新年好,我的朋友们,\n哈,哈,哈!", Toast.LENGTH_LONG);
- textToast.show();
- break;
- case R.id.btnImageToast:
- View view = getLayoutInflater().inflate(R.layout.toast, null);
- TextView textView = (TextView) view.findViewById(R.id.smart);
- //使用TOAST方法显示结果内容
- textView.setText("新年好,我的朋友们,\n哈,哈,哈!");
- Toast toast = new Toast(this);
- toast.setDuration(Toast.LENGTH_LONG);
- toast.setView(view);
- toast.show();
- break;
- }
- }
- }
本文转自 llb988 51CTO博客,原文链接:http://blog.51cto.com/llb988/489546,如需转载请自行联系原作者