自定义样式 dialog
自定义样式 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: [email protected] */ 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);
效果图:
git 源码下载
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' }
相关推荐
hanliuxinming 2014-05-30
asdjkl 2014-02-13
delmarks 2012-03-05
apowerfulman 2020-03-03
hustlei 2011-03-03
Mexican 2011-08-31
larrywangsun 2011-08-09
TTHHVV 2011-09-28
87384559 2014-11-11
xuewenke 2015-11-04
火星的你 2015-10-25
王磊的程序员之路 2019-06-19
十一郎的IT 2013-10-29
攻城师 2019-06-28
89453862 2016-05-13