简介
这是一个基于alertdialog和dialog这两个类封装的多种弹出框样式,其中提供各种简单样式的弹出框使用说明。同时也可自定义弹出框。
项目地址:
特性
1.使用链式开发代码简洁明了
2.所有的弹出框样式都在dialoguiutils这个类中完成,方便查阅方法
3.可以自定义弹出框字体样式
4.简单的类似加载框的样式可以支持两种主题更改默认白色和灰色
截图
demo下载
demo apk下载
download or grab via maven:
<dependency> <groupid>com.dou361.dialogui</groupid> <artifactid>jjdxm-dialogui</artifactid> <version>x.x.x</version> </dependency>
or gradle:
compile 'com.dou361.dialogui:jjdxm-dialogui:x.x.x'
历史版本:
compile 'com.dou361.dialogui:jjdxm-dialogui:1.0.1'
compile 'com.dou361.dialogui:jjdxm-dialogui:1.0.0'
jjdxm-dialogui requires at minimum java 9 or android 2.3.
架包的打包引用以及冲突解决
代码混淆
根据你的混淆器配置和使用,您可能需要在你的proguard文件内配置以下内容:
-keep class com.dou361.** { *; }
androidstudio代码混淆注意的问题
快速开始
step1
如果需要使用toast类,采用单例模式的,多次调用toast后只会显示一个,需要初始化dialoguiutils类,否则会抛异常,使用前初始化即可,代码如下
dialoguiutils.init(appcontext);
step2
如果不需要使用toast类,可以不操作step1,直接使用相对于的弹出框即可。以下分别是部分弹出框的调用代码案例。
自定义弹出框
/** * 自定义弹出框 默认居中可取消可点击 * * @param context 上下问 * @param contentview 自定义view * @return */ public static buildbean showcustomalert(context context, view contentview) /** * 自定义弹出框 默认可取消可点击 * * @param context 上下文 * @param contentview 自定义view * @param gravity 显示window的位置例如gravity.center * @return */ public static buildbean showcustomalert(context context, view contentview, int gravity) /*** * 自定义弹出框 * * @param context 上下文 * @param contentview 自定义view * @param gravity 显示window的位置例如gravity.center * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @return */ public static buildbean showcustomalert(context context, view contentview, int gravity, boolean cancleable, boolean outsidetouchable)
具体使用
view rootview = view.inflate(activity, r.layout.custom_dialog_layout, null); dialoguiutils.showcustomalert(this, rootview).show();
弹出toast
/** * 弹出toast 默认白色背景可取消可点击 * * @param context 上下文 * @param msg 提示文本 */ public static buildbean showtoasttie(context context, charsequence msg) /** * 弹出toast 默认可取消可点击 * * @param context 上下文 * @param msg 提示文本 * @param iswhitebg true为白色背景false为灰色背景 */ public static buildbean showtoasttie(context context, charsequence msg, boolean iswhitebg) /** * 弹出toast * * @param context 上下文 * @param msg 提示文本 * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @param iswhitebg true为白色背景false为灰色背景 */ public static buildbean showtoasttie(context context, charsequence msg, boolean cancleable, boolean outsidetouchable, boolean iswhitebg)
具体使用
dialoguiutils.showtoasttie(this, "加载中...").show();
横向加载框
/** * 横向加载框 默认白色背景可取消可点击 * * @param context 上下文 * @param msg 提示文本 */ public static buildbean showloadinghorizontal(context context, charsequence msg) /** * 横向加载框 默认可取消可点击 * * @param context 上下文 * @param msg 提示文本 * @param iswhitebg true为白色背景false为灰色背景 */ public static buildbean showloadinghorizontal(context context, charsequence msg, boolean iswhitebg) /** * 横向加载框 * * @param context 上下文 * @param msg 提示文本 * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @param iswhitebg true为白色背景false为灰色背景 */ public static buildbean showloadinghorizontal(context context, charsequence msg, boolean cancleable, boolean outsidetouchable, boolean iswhitebg)
具体使用
dialoguiutils.showloadinghorizontal(this, "加载中...").show();
md风格横向加载框
/** * md风格横向加载框 默认白色背景可取消可点击 * * @param context 上下文 * @param msg 提示文本 */ public static buildbean showmdloadinghorizontal(context context, charsequence msg) /** * md风格横向加载框 默认可取消可点击 * * @param context 上下文 * @param msg 提示文本 * @param iswhitebg true为白色背景false为灰色背景 */ public static buildbean showmdloadinghorizontal(context context, charsequence msg, boolean iswhitebg) /** * md风格横向加载框 * * @param context 上下文 * @param msg 提示文本 * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @param iswhitebg true为白色背景false为灰色背景 */ public static buildbean showmdloadinghorizontal(context context, charsequence msg, boolean cancleable, boolean outsidetouchable, boolean iswhitebg)
具体使用
dialoguiutils.showmdloadinghorizontal(this, "加载中...").show();
竖向加载框
/** * 竖向加载框 默认白色背景可取消可点击 * * @param context 上下文 * @param msg 提示文本 */ public static buildbean showloadingvertical(context context, charsequence msg) /** * 竖向加载框 默认可取消可点击 * * @param context 上下文 * @param msg 提示文本 * @param iswhitebg true为白色背景false为灰色背景 */ public static buildbean showloadingvertical(context context, charsequence msg, boolean iswhitebg) /** * 竖向加载框 * * @param context 上下文 * @param msg 提示文本 * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @param iswhitebg true为白色背景false为灰色背景 */ public static buildbean showloadingvertical(context context, charsequence msg, boolean cancleable, boolean outsidetouchable, boolean iswhitebg)
具体使用
dialoguiutils.showloadingvertical(this, "加载中...").show();
md风格竖向加载框
/** * md风格竖向加载框 默认白色背景可取消可点击 * * @param context 上下文 * @param msg 提示文本 */ public static buildbean showmdloadingvertical(context context, charsequence msg) /** * md风格竖向加载框 默认可取消可点击 * * @param context 上下文 * @param msg 提示文本 * @param iswhitebg true为白色背景false为灰色背景 */ public static buildbean showmdloadingvertical(context context, charsequence msg, boolean iswhitebg) /** * md风格竖向加载框 * * @param context 上下文 * @param msg 提示文本 * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @param iswhitebg true为白色背景false为灰色背景 */ public static buildbean showmdloadingvertical(context context, charsequence msg, boolean cancleable, boolean outsidetouchable, boolean iswhitebg)
具体使用
dialoguiutils.showmdloadingvertical(this, "加载中...").show();
md风格弹出框
/*** * md风格弹出框 默认可取消可点击 * * @param activity 所在activity * @param title 标题 不传则无标题 * @param msg 消息 * @param listener 事件监听 * @return */ public static buildbean showmdalert(activity activity, charsequence title, charsequence msg, dialoguilistener listener) /*** * md风格弹出框 * * @param activity 所在activity * @param title 标题 不传则无标题 * @param msg 消息 * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @param listener 事件监听 * @return */ public static buildbean showmdalert(activity activity, charsequence title, charsequence msg, boolean cancleable, boolean outsidetouchable, dialoguilistener listener)
具体使用
dialoguiutils.showmdalert(activity, "标题", "文本内容", new dialoguilistener() { @override public void onpositive() { } @override public void onnegative() { } }).show();
md风格多选框
/** * md风格多选框 默认可取消可点击 * * @param activity 所在activity * @param title 标题 不传则无标题 * @param words 消息数组 * @param checkeditems 默认选中项 * @param listener 事件监听 */ public static buildbean showmdmultichoose(activity activity, charsequence title, charsequence[] words, boolean[] checkeditems, dialoguilistener listener) /*** * md风格多选框 * * @param activity 所在activity * @param title 标题 不传则无标题 * @param words 消息数组 * @param checkeditems 默认选中项 * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @param listener 事件监听 * @return */ public static buildbean showmdmultichoose(activity activity, charsequence title, charsequence[] words, boolean[] checkeditems, boolean cancleable, boolean outsidetouchable, dialoguilistener listener)
具体使用
string[] words = new string[]{"1", "2", "3"}; boolean[] chosedefault = new boolean[]{false, false, false}; dialoguiutils.showmdmultichoose(activity, "标题", words, chosedefault, new dialoguilistener() { @override public void onpositive() { } @override public void onnegative() { } }).show();
单选框
/** * 单选框 默认可取消可点击 * * @param activity 所在activity * @param title 标题 不传则无标题 * @param defaultchosen 默认选中项 * @param words 消息数组 * @param listener 事件监听 */ public static buildbean showsinglechoose(activity activity, charsequence title, int defaultchosen, charsequence[] words, dialoguiitemlistener listener) /** * 单选框 * * @param activity 所在activity * @param title 标题 不传则无标题 * @param defaultchosen 默认选中项 * @param words 消息数组 * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @param listener 事件监听 */ public static buildbean showsinglechoose(activity activity, charsequence title, int defaultchosen, charsequence[] words, boolean cancleable, boolean outsidetouchable, dialoguiitemlistener listener)
具体使用
string[] words2 = new string[]{"1", "2", "3"}; dialoguiutils.showsinglechoose(activity, "单选", 0, words2, new dialoguiitemlistener() { @override public void onitemclick(charsequence text, int position) { showtoast(text + "--" + position); } }).show();
提示弹出框
/** * 提示弹出框 默认可取消可点击 * * @param activity 所在activity * @param title 标题 不传则无标题 * @param listener 事件监听 */ public static buildbean showalert(activity activity, charsequence title, charsequence msg, dialoguilistener listener) /** * 提示弹出框 * * @param activity 所在activity * @param title 标题 不传则无标题 * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @param listener 事件监听 */ public static buildbean showalert(activity activity, charsequence title, charsequence msg, boolean cancleable, boolean outsidetouchable, dialoguilistener listener)
具体使用
dialoguiutils.showalert(activity, "标题", "文本内容", new dialoguilistener() { @override public void onpositive() { } @override public void onnegative() { } }).show();
横向弹出框
/** * 横向弹出框 默认可取消可点击 * * @param activity 所在activity * @param title 标题 不传则无标题 * @param msg 消息 * @param listener 事件监听 */ public static buildbean showalerthorizontal(context activity, charsequence title, charsequence msg, dialoguilistener listener) /** * 横向弹出框 * * @param activity 所在activity * @param title 标题 不传则无标题 * @param msg 消息 * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @param listener 事件监听 */ public static buildbean showalerthorizontal(context activity, charsequence title, charsequence msg, boolean cancleable, boolean outsidetouchable, dialoguilistener listener)
具体使用
dialoguiutils.showalerthorizontal(activity, "标题", "文本内容", new dialoguilistener() { @override public void onpositive() { } @override public void onnegative() { } }).show();
竖向弹出框
/** * 竖向弹出框 默认可取消可点击 * * @param activity 所在activity * @param title 标题 不传则无标题 * @param msg 消息 * @param listener 事件监听 */ public static buildbean showalertvertical(context activity, charsequence title, charsequence msg, dialoguilistener listener) /** * 竖向弹出框 * * @param activity 所在activity * @param title 标题 不传则无标题 * @param msg 消息 * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @param listener 事件监听 */ public static buildbean showalertvertical(context activity, charsequence title, charsequence msg, boolean cancleable, boolean outsidetouchable, dialoguilistener listener)
具体使用
dialoguiutils.showalertvertical(activity, "标题", "文本内容", new dialoguilistener() { @override public void onpositive() { } @override public void onnegative() { } }).show();
中间弹出列表
/** * 中间弹出列表 默认可取消可点击 * * @param context 上下文 * @param words 素组集合 * @param listener 事件监听 * @return */ public static buildbean showcentersheet(context context, list<? extends charsequence> words, dialoguiitemlistener listener) /*** * 中间弹出列表 * * @param context 上下文 * @param words 素组集合 * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @param listener 事件监听 * @return */ public static buildbean showcentersheet(context context, list<? extends charsequence> words, boolean cancleable, boolean outsidetouchable, dialoguiitemlistener listener)
具体使用
list<string> strings = new arraylist<>(); strings.add("1"); strings.add("2"); strings.add("3"); dialoguiutils.showcentersheet(activity, strings, new dialoguiitemlistener() { @override public void onitemclick(charsequence text, int position) { } @override public void onbottombtnclick() { } }).show();
带取消的底部弹出列表
/** * 带取消的底部弹出列表 默认可取消可点击 * * @param context 上下文 * @param words 素组集合 * @param bottomtxt 底部按钮文本 * @param listener 事件监听 * @return */ public static buildbean showbottomsheetandcancel(context context, list<? extends charsequence> words, charsequence bottomtxt, dialoguiitemlistener listener) /*** * 带取消的底部弹出列表 * * @param context 上下文 * @param words 素组集合 * @param bottomtxt 底部按钮文本 * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @param listener 事件监听 * @return */ public static buildbean showbottomsheetandcancel(context context, list<? extends charsequence> words, charsequence bottomtxt, boolean cancleable, boolean outsidetouchable, dialoguiitemlistener listener)
具体使用
list<string> strings = new arraylist<>(); strings.add("1"); strings.add("2"); strings.add("3"); dialoguiutils.showbottomsheetandcancel(activity, strings, "取消", new dialoguiitemlistener() { @override public void onitemclick(charsequence text, int position) { } @override public void onbottombtnclick() { } }).show();
底部弹出列表
/** * 底部弹出列表 默认可取消可点击 * * @param context 上下文 * @param datas 集合需要bottomsheetbean对象 * @param listener 事件监听 * @return */ public static buildbean showbottomsheet(activity context, list datas, dialoguiitemlistener listener) /*** * 底部弹出列表 * * @param context 上下文 * @param datas 集合需要bottomsheetbean对象 * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @param listener 事件监听 * @return */ public static buildbean showbottomsheet(activity context, list datas, boolean cancleable, boolean outsidetouchable, dialoguiitemlistener listener)
具体使用
list<bottomsheetbean> datass = new arraylist<>(); datass.add(new bottomsheetbean(0, "1")); datass.add(new bottomsheetbean(0, "2")); datass.add(new bottomsheetbean(0, "3")); dialoguiutils.showbottomsheet(this, datass, new dialoguiitemlistener() { @override public void onitemclick(charsequence text, int position) { } }).show();
输入框
/** * 输入框 默认可取消可点击 * * @param context 上下文 * @param title 标题 * @param hint1 第一个文本框提示语 * @param hint2 第二个文本框提示语 * @param firsttxt 第一个按钮文本 * @param secondtxt 第二个按钮文本 * @param listener 事件监听 * @return */ public static buildbean showalertinput(context context, charsequence title, charsequence hint1, charsequence hint2, charsequence firsttxt, charsequence secondtxt, dialoguilistener listener) /*** * 输入框 * * @param context 上下文 * @param title 标题 * @param hint1 第一个文本框提示语 * @param hint2 第二个文本框提示语 * @param firsttxt 第一个按钮文本 * @param secondtxt 第二个按钮文本 * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @param listener 事件监听 * @return */ public static buildbean showalertinput(context context, charsequence title, charsequence hint1, charsequence hint2, charsequence firsttxt, charsequence secondtxt, boolean cancleable, boolean outsidetouchable, dialoguilistener listener)
具体使用
dialoguiutils.showalertinput(activity, "登录", "请输入用户名", "请输入密码", "登录", "取消", new dialoguilistener() { @override public void onpositive() { } @override public void onnegative() { } @override public void ongetinput(charsequence input1, charsequence input2) { } }).show();
md风格竖向底部弹出列表
/** * md风格竖向底部弹出列表 默认可取消可点击 * * @param context 上下文 * @param title 标题 * @param datas 集合需要bottomsheetbean对象 * @param bottomtxt 底部item文本 * @param listener 事件监听 * @return */ public static buildbean showmdbottomsheetvertical(context context, charsequence title, list datas, charsequence bottomtxt, dialoguiitemlistener listener) /*** * md风格竖向底部弹出列表 * * @param context 上下文 * @param title 标题 * @param datas 集合需要bottomsheetbean对象 * @param bottomtxt 底部item文本 * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @param listener 事件监听 * @return */ public static buildbean showmdbottomsheetvertical(context context, charsequence title, list datas, charsequence bottomtxt, boolean cancleable, boolean outsidetouchable, dialoguiitemlistener listener)
具体使用
list<bottomsheetbean> datass = new arraylist<>(); datass.add(new bottomsheetbean(0, "1")); datass.add(new bottomsheetbean(0, "2")); datass.add(new bottomsheetbean(0, "3")); dialoguiutils.showmdbottomsheetvertical(this, datass, new dialoguiitemlistener() { @override public void onitemclick(charsequence text, int position) { } }).show();
md风格横向底部弹出列表
/** * md风格横向底部弹出列表 默认可取消可点击 * * @param context 上下文 * @param title 标题 * @param datas 集合需要bottomsheetbean对象 * @param bottomtxt 底部item文本 * @param columnsnum 列数量 * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @param listener 事件监听 * @return */ public static buildbean showmdbottomsheethorizontal(context context, charsequence title, list datas, charsequence bottomtxt, int columnsnum, dialoguiitemlistener listener) /*** * md风格横向底部弹出列表 * * @param context 上下文 * @param title 标题 * @param datas 集合需要bottomsheetbean对象 * @param bottomtxt 底部item文本 * @param columnsnum 列数量 * @param cancleable true为可以取消false为不可取消 * @param outsidetouchable true为可以点击空白区域false为不可点击 * @param listener 事件监听 * @return */ public static buildbean showmdbottomsheethorizontal(context context, charsequence title, list datas, charsequence bottomtxt, int columnsnum, boolean cancleable, boolean outsidetouchable, dialoguiitemlistener listener)
具体使用
list<bottomsheetbean> datass = new arraylist<>(); datass.add(new bottomsheetbean(0, "1")); datass.add(new bottomsheetbean(0, "2")); datass.add(new bottomsheetbean(0, "3")); dialoguiutils.showmdbottomsheethorizontal(this, datass, new dialoguiitemlistener() { @override public void onitemclick(charsequence text, int position) { } }).show();
项目地址:
以上所述是小编给大家介绍的android 多种简单的弹出框样式设置代码,数据库显示空白的完美解决方案(图文教程),希望对大家有所帮助
如对本文有疑问, 点击进行留言回复!!
网友评论