1.Toasty
颜色醒目的toast
左边有简单好看的小动画
3.ToastUtils
自定义实现上面图片下面文字的toast
public class ToastUtils {
private static Context mContext = MyApplication.getContext();
public static void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
/**
* 带图片的吐司提示
* @param text
*/
public static void showCustomImgToast(String text) {
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(R.layout.toast_view, null);
ImageView imageView = (ImageView) view.findViewById(R.id.toast_image);
imageView.setBackgroundResource(R.drawable.icon_success);
TextView t = (TextView) view.findViewById(R.id.toast_text);
t.setText(text);
Toast toast = null;
if (toast != null) {
toast.cancel();
}
toast = new Toast(mContext);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(view);
toast.show();
}
/**
* 带图片的吐司提示
* 通过参数传递,可是设置吐司的图片和文字内容
* @param text
*/
public static void showCustomImgToast(String text,int imgResId) {
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(R.layout.toast_view, null);
ImageView imageView = (ImageView) view.findViewById(R.id.toast_image);
imageView.setBackgroundResource(R.drawable.icon_success);
TextView t = (TextView) view.findViewById(R.id.toast_text);
t.setText(text);
Toast toast = null;
if (toast != null) {
toast.cancel();
}
toast = new Toast(mContext);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(view);
toast.show();
}
/**
* 不带图片的吐司提示
* @param text
*/
public static void showCustomToast(String text) {
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(R.layout.toast_view, null);
ImageView imageView = (ImageView) view.findViewById(R.id.toast_image);
imageView.setVisibility(View.GONE);
TextView t = (TextView) view.findViewById(R.id.toast_text);
t.setText(text);
Toast toast = null;
if (toast != null) {
toast.cancel();
}
toast = new Toast(mContext);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(view);
toast.show();
}
/**
* 带图片的吐司,设置吐司弹出的位置为屏幕中心
* @param text
*/
public static void showCustomToastCenter(String text) {
showCustomToastCenter(text, R.drawable.icon_success);
}
/**
* 带图片的吐司,设置吐司弹出的位置为屏幕中心
* 通过参数传递,可是设置吐司的图片和文字内容
* @param text
*/
public static void showCustomToastCenter(String text, int imgResId) {
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(R.layout.toast_view, null);
ImageView imageView = (ImageView) view.findViewById(R.id.toast_image);
imageView.setBackgroundResource(imgResId);
TextView t = (TextView) view.findViewById(R.id.toast_text);
t.setText(text);
Toast toast = null;
if (toast != null) {
toast.cancel();
}
toast = new Toast(mContext);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(view);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
}
简洁优雅可点击的toast控件,支持加载GIF
上中下不同位置不同颜色的toast
顶部消息提示,滑动消失
7.KToast