标签:builder ext context stat repos turn sans 点击 url
自定义样式 dialog,可设置界面外点击屏幕外和返回键 是否消失
基本用法如下:
CustomDialog.Builder customBuilder = new CustomDialog.Builder(context); customBuilder.setTitle(title) .setMessage(content) .setNegativeButton(cancelText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (cancelListener != null) cancelListener.onClick(dialog, which); } }) .setPositiveButton(okText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (okListener != null) okListener.onClick(dialog, which); } }); CustomDialog dialog = customBuilder.create(); dialog.setCancelable(isAutoDissmiss); dialog.show();
Utils 工具类封装:
CustomDialogUtil.java
/** * Created by dingzuoqiang on 2017/6/20. * Email: 530858106@qq.com */ public class CustomDialogUtil { /** * final Context context, * String content, * String okText, * String cancelText, * final DialogInterface.OnClickListener okListener * final DialogInterface.OnClickListener cancelListener * boolean isAutoDissmiss */ public static View normalDialog(final Context context, String title, String content, String okText, String cancelText, final DialogInterface.OnClickListener okListener, final DialogInterface.OnClickListener cancelListener, boolean isAutoDissmiss) { CustomDialog.Builder customBuilder = new CustomDialog.Builder(context); customBuilder.setTitle(title) .setMessage(content) .setNegativeButton(cancelText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (cancelListener != null) cancelListener.onClick(dialog, which); } }) .setPositiveButton(okText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (okListener != null) okListener.onClick(dialog, which); } }); CustomDialog dialog = customBuilder.create(); dialog.setCancelable(isAutoDissmiss); dialog.show(); return dialog.getWindow().getDecorView(); } }
CustomDialogUtil.normalDialog(MainActivity.this, "Title", "啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊", "确定", "取消", onClickListener, null, true);
效果图:
To get a Git project into your build:
Step 1. Add the JitPack repository to your build file
allprojects { repositories { ... maven { url ‘https://jitpack.io‘ } } }
Step 2. Add the dependency
dependencies { compile ‘com.github.dingzuoqiang:CustomDialog:v1.0‘ }
CustomDialog.Builder customBuilder = new CustomDialog.Builder(context);
customBuilder.setTitle(title)
.setMessage(content)
.setNegativeButton(cancelText, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (cancelListener != null)
cancelListener.onClick(dialog, which);
}
})
.setPositiveButton(okText,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (okListener != null)
okListener.onClick(dialog, which);
}
});
CustomDialog dialog = customBuilder.create();
dialog.setCancelable(isAutoDissmiss);
dialog.show();
标签:builder ext context stat repos turn sans 点击 url
原文地址:http://www.cnblogs.com/dingzq/p/7081610.html