1.很久没有写博客,从今天爱商天天 最少一篇博客。
2.今天看到一个自定义的Toast 把他写成博客。
主要方法
package com.wudl.customtoasts;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class CustomToasts {
private Context mycontext;
public CustomToasts(Context context) {
super();
mycontext = context;
}
public void CreateToasts(String message, LayoutInflater inflater) {
// 加载容器
View inflate = inflater.inflate(R.layout.toasts, null);
TextView tv = (TextView) inflate.findViewById(R.id.txt);
tv.setText(message);
// 设置Toast
Toast toast = new Toast(mycontext);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(inflate);
toast.show();
}
}
源代码下载地址为,http://download.csdn.net/detail/helloworld_i_android/9522150