Toast内容顯示圖
<a target="_blank" href="http://blog.51cto.com/attachment/201102/155211797.jpg"></a>
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);
}
//點選方法事件
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);
textView.setText("新年好,我的朋友們,\n哈,哈,哈!");
Toast toast = new Toast(this);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(view);
toast.show();
}
}
本文轉自 llb988 51CTO部落格,原文連結:http://blog.51cto.com/llb988/489546,如需轉載請自行聯系原作者