/**
*
* @param context
* @param text 直接传字符串
* @param resId 图片ID
*/
public static void showTwo(Context context, String text,int resId) {
LayoutInflater inflater = LayoutInflater.from(context);
View layout = inflater.inflate(R.layout.toast_layout_two, null);
toast_image = (ImageView) layout.findViewById(R.id.toast_image);
//图片可以自己从外面传递进来换;
toast_image.setBackgroundResource(resId);
textV = (TextView) layout.findViewById(R.id.toast_text);
textV.setText(text);
if (mToast == null) {
mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
mToast.setGravity(Gravity.CENTER, 0, 0);
mToast.setView(layout);
} else {
mToast.cancel();//关闭吐司显示
mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
//设置Toast位置的,如若不设置将会是系统默认Toast位置
mToast.setGravity(Gravity.CENTER, 0, 0);
mToast.setView(layout);
}
mToast.show();
}
/**
* 传字段ID
* @param context
* @param text 文字ID
* @param resId 图片ID
*/
public static void showTwo(Context context, int text,int resId) {
LayoutInflater inflater = LayoutInflater.from(context);
View layout = inflater.inflate(R.layout.toast_layout_two, null);
toast_image = (ImageView) layout.findViewById(R.id.toast_image);
//图片可以自己从外面传递进来换;
toast_image.setBackgroundResource(resId);
TextView textV = (TextView) layout.findViewById(R.id.toast_text);
textV.setText(text);
if (mToast == null) {
mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
mToast.setGravity(Gravity.CENTER, 0, 0);
mToast.setView(layout);
} else {
mToast.cancel();//关闭吐司显示
mToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
//设置Toast位置的
mToast.setGravity(Gravity.CENTER, 0, 0);
mToast.setView(layout);
}
mToast.show();
}
源码下载地址:(初次发文,多多关注)
http://download.csdn.net/detail/qq_31850557/9532987