一個快速建立對話框的工具類庫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