温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Dialog与Toast封装类

发布时间:2020-07-14 13:48:17 来源:网络 阅读:523 作者:671076656 栏目:开发技术

由于在项目中会经常用到dialog和toast

在这里对这两个做了一个封装。

方便后面直接调用。

public class AlertUtil {

private static Context mContext;

public static void showToast(Context context,String text){

mContext = context;

Toast.makeText(mContext, text, Toast.LENGTH_SHORT).show();

}

public static void showAlertDialog(final Context mContext,String text){

new AlertDialog.Builder(mContext)

.setTitle("提示")

.setMessage(text)

.setPositiveButton("确定", new OnClickListener(){


@Override

public void onClick(DialogInterface arg0, int arg1) {

// TODO Auto-generated method stub

showToast(mContext, "choose ok");

}

})

.create()

.show();

}

}

//调用方法如下

1、AlertUtil.showToast(this, "show toast");

2、AlertUtil.showAlertDialog(this, "show dialog");

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI