1,添加依赖
compile 'com.github.the-pig-of-jungle.smart-show:toast:2.8.3'
2,在application中初始化
SmartShow.init(this);
SmartToast.setting()
.dismissOnLeave(true); // 离开当前Activity,Toast自动消失
3,工具类
public class ToastUtils {
// 默认底部显示
public static void ToastShow(CharSequence msg){
SmartToast.show(msg);
}
public static void ToastShow(int msg){
SmartToast.show(msg);
}
public static void ToastShowLong(CharSequence msg){
SmartToast.show(msg);
}
public static void ToastShowLong(int msg){
SmartToast.show(msg);
}
// 中间显示
public static void showInCenter(CharSequence msg){
SmartToast.showInCenter(msg);
}
public static void showInCenter(int msg){
SmartToast.showInCenter(msg);
}
public static void showInCenterLong(CharSequence msg){
SmartToast.showLongInCenter(msg);
}
public static void showInCenterLong(int msg){
SmartToast.showLongInCenter(msg);
}
// 顶部显示
public static void showAtTop(CharSequence msg){
SmartToast.showAtTop(msg);
}
public static void showAtTop(int msg){
SmartToast.showAtTop(msg);
}
public static void showAtTopLong(CharSequence msg){
SmartToast.showLongAtTop(msg);
}
public static void showAtTopLong(int msg){
SmartToast.showLongAtTop(msg);
}
//如,在左上角,x,y偏移量为10dp的位置显示
// SmartToast.showAtLocation(msg,Gravity.LEFT | Gravity.TOP,10,10);
// 自定义显示位置
public static void showAtLocation(CharSequence msg, int gravity, float xOffsetDp, float yOffsetDp){
SmartToast.showAtLocation(msg,gravity,xOffsetDp,yOffsetDp);
}
public static void showAtLocation(int msg, int gravity, float xOffsetDp, float yOffsetDp){
SmartToast.showAtLocation(msg,gravity,xOffsetDp,yOffsetDp);
}
public static void showLongAtLocation(CharSequence msg, int gravity, float xOffsetDp, float yOffsetDp){
SmartToast.showLongAtLocation(msg,gravity,xOffsetDp,yOffsetDp);
}
public static void showLongAtLocation(int msg, int gravity, float xOffsetDp, float yOffsetDp){
SmartToast.showLongAtLocation(msg,gravity,xOffsetDp,yOffsetDp);
}
}
顶部弹出的SnackBar工具类:
添加依赖
compile 'com.github.the-pig-of-jungle.smart-show:topbar:2.8.3'
在application中初始化初始化:
SmartTopbar.setting()
.backgroundColorRes(R.color.colorPrimary) // 设置背景颜色
.msgTextColorRes(R.color.colorAccent) // 设置消息文本颜色
.msgTextSizeSp(14) // 设置消息文本大小
.actionColorRes(R.color.colorAccent) // 设置动作文本颜色
.actionSizeSp(14) // 设置动作文本大小
.dismissOnLeave(true); // 离开当前Activity,Toast自动消失
public class TopSnackBarUtils {
// 单纯显示一句提示
public static void show(Activity activity,CharSequence msg){
SmartTopbar.get(activity).show(msg); // 和Toast一样,会自动消失
}
public static void showAction(Activity activity, CharSequence msg, CharSequence msgaction, View.OnClickListener clist){
SmartTopbar.get(activity).showIndefinite(msg, msgaction,clist); // 不会消失,点击action才会消失
}
}