一个快速建立对话框的工具类库git
效果图以下:github
引入依赖库bash
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}复制代码
dependencies {
compile 'com.github.yilylong:CBDialog:v1.0.2'
}复制代码
new CBDialogBuilder(this)
.setTouchOutSideCancelable(true)
.showCancelButton(true)
.setTitle("这是一个普通样式的对话框")
.setMessage("this is a normal CBDialog")
.setConfirmButtonText("肯定")
.setCancelButtonText("取消")
.setDialogAnimation(CBDialogBuilder.DIALOG_ANIM_SLID_BOTTOM)
.create().show();复制代码
能够传入不一样的样式微信
CBDialogBuilder.DIALOG_STYLE_NORMAL
CBDialogBuilder.DIALOG_STYLE_PROGRESS
CBDialogBuilder.DIALOG_STYLE_PROGRESS_TITANIC
CBDialogBuilder.DIALOG_STYLE_PROGRESS_AVLOADING
new CBDialogBuilder(this, CBDialogBuilder.DIALOG_STYLE_PROGRESS_TITANIC).create();
.setTouchOutSideCancelable(true) 设置是否点击对话框之外的区域dismiss对话框
.showCancelButton(true) 是否显示取消按钮
.setDialogAnimation(CBDialogBuilder.DIALOG_ANIM_SLID_BOTTOM) 设置对话框的动画样式
.setDialoglocation(CBDialogBuilder.DIALOG_LOCATION_BOTTOM) 设置对话框位于屏幕的位置
.setButtonClickListener(true, new CBDialogBuilder.onDialogbtnClickListener() { 添加按钮回调监听
@Override
public void onDialogbtnClick(Context context, Dialog dialog, int whichBtn) {
switch (whichBtn) {
case BUTTON_CONFIRM:
Toast.makeText(context, "点击了确认按钮", Toast.LENGTH_SHORT).show();
break;
case BUTTON_CANCEL:
Toast.makeText(context, "点击了取消按钮", Toast.LENGTH_SHORT).show();
break;
default:
break;
}
}
})复制代码
设置一个列表 和 列表项选中回调监听maven
.setItems(new String[]{"较小", "中等", "较大", "巨无霸"}, new CBDialogBuilder.onDialogItemClickListener() {
@Override
public void onDialogItemClick(CBDialogBuilder.DialogItemAdapter ItemAdapter,Context context, CBDialogBuilder dialogbuilder, Dialog dialog,int position) {
//TODO 保存选中设置
dialog.dismiss();
}
}, 2)复制代码
.setOnProgressOutTimeListener(5, new CBDialogBuilder.onProgressOutTimeListener() {
@Override
public void onProgressOutTime(Dialog dialog, TextView dialogMsgTextView) {
// do your work
}
})复制代码
.setProgressIndicatorColor(0xaa198675)
.setProgressIndicator(CBDialogBuilder.INDICATOR_BallRotate)复制代码
设置自定义的dialog布局文件ide
在构建的时候传入R.layout.layout_custom_dialog_layout自定义布局文件便可,可是里面的个控件(标题,消息,按钮)的ID要跟cb_dialog.xml 里面一致工具
new CBDialogBuilder(this, R.layout.layout_custom_dialog_layout, 1.0f)
...
.create().show();复制代码
.setView(R.layout.custom_msg_view)复制代码
项目地址布局
若是你以为此文对您有所帮助,欢迎入群 QQ交流群 :644196190
微信公众号:终端研发部 ui