对话框是一个软件对用户操作进行响应、反馈的重要组件,而 DialogX 将可以协助开发者快速完成这些事务。
我们力求减少开发者所需要担心的,所需要顾虑的,而打造一款可以在任意时间,任意情况都能轻松使用的对话框组件。
在轻松使用的前提下,DialogX 提供了更多的个性接口方便开发者进行扩展,包括在对话框内插入自定义布局,亮暗色模式的切换,甚至自定义更符合 App UI 的自定义主题。
开源地址:https://github.com/kongzue/DialogX
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' } //增加 jitPack Maven 仓库
}
}
//https://github.com/kongzue/DialogX
def dialogx_version = "0.0.45"
implementation "com.github.kongzue.DialogX:DialogX:${dialogx_version}"
implementation "com.github.kongzue.DialogX:DialogXIOSStyle:${dialogx_version}"
implementation "com.github.kongzue.DialogX:DialogXKongzueStyle:${dialogx_version}"
implementation "com.github.kongzue.DialogX:DialogXMIUIStyle:${dialogx_version}"
DialogX.init(this)
DialogX.globalStyle = IOSStyle.style()
DialogX.globalStyle = IOSStyle.style();
MessageDialog.show("标题", "这里是正文内容。", "确定")
.setOkButton(new OnDialogButtonClickListener<MessageDialog>() {
@Override
public boolean onClick(MessageDialog baseDialog, View v) {
PopTip.show("点击确定按钮");
return false;
}
});
DialogX.globalStyle = IOSStyle.style();
MessageDialog messageDialog = new MessageDialog("多选对话框", "移除App会将它从主屏幕移除并保留其所有数据。", "删除App", "取消", "移至App资源库")
.setButtonOrientation(LinearLayout.VERTICAL);
if (!rdoMiui.isChecked()) {
messageDialog.setOkTextInfo(new TextInfo().setFontColor(Color.parseColor("#EB5545")).setBold(true));
}
messageDialog.show();
DialogX.globalStyle = MaterialStyle.style();
btnInputDialog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new InputDialog("标题", "正文内容", "确定", "取消", "正在输入的文字")
.setInputText("Hello World")
.setOkButton(new OnInputDialogButtonClickListener<InputDialog>() {
@Override
public boolean onClick(InputDialog baseDialog, View v, String inputStr) {
PopTip.show("输入的内容:" + inputStr);
return false;
}
})
.show();
}
});
//正确
TipDialog.show(msg, WaitDialog.TYPE.SUCCESS)
//错误
TipDialog.show(msg, WaitDialog.TYPE.ERROR)
DialogX.globalStyle = MaterialStyle.style();
PopTip.show("这是一个提示");
PopTip.show(R.mipmap.img, "一个提示").setAutoTintIconInLightOrDarkMode(false).showLong();
//view是指显示在哪个view上面
DialogX.globalStyle = MaterialStyle.style();
PopMenu.show(view, new String[]{"选项1", "选项2", "选项3"})
.setOnMenuItemClickListener(new OnMenuItemClickListener<PopMenu>() {
@Override
public boolean onClick(PopMenu dialog, CharSequence text, int index) {
btnSelectMenu.setText(text);
return false;
}
});
//设置菜单并且给菜单设置图标
DialogX.globalStyle = MaterialStyle.style();
PopMenu.show(new String[]{"添加", "编辑", "删除", "分享"})
.setOnMenuItemClickListener(new OnMenuItemClickListener<PopMenu>() {
@Override
public boolean onClick(PopMenu dialog, CharSequence text, int index) {
if (index==0){
dialog.setMenuList(new String[]{"A","B","C"});
return true;
}
return false;
}
})
.setOnIconChangeCallBack(new OnIconChangeCallBack<PopMenu>(true) {
@Override
public int getIcon(PopMenu dialog, int index, String menuText) {
switch (menuText) {
case "添加":
return R.mipmap.img_dialogx_demo_add;
case "编辑":
return R.mipmap.img_dialogx_demo_edit;
case "删除":
return R.mipmap.img_dialogx_demo_delete;
case "分享":
return R.mipmap.img_dialogx_demo_share;
default:
return 0;
}
}
});
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_root"
android:layout_width="match_parent"
android:layout_height="500dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp"
android:text="我是余静"
android:textColor="@color/black"
android:textSize="16sp" />
<com.kongzue.dialogxdemo.custom.recycleview.CustomRecycleView
android:id="@+id/recycleView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:tag="ScrollController">
com.kongzue.dialogxdemo.custom.recycleview.CustomRecycleView>
LinearLayout>
List<CustomRecycleViewAdapter.Data> list = new ArrayList<>();
list.add(new CustomRecycleViewAdapter.Data("Item Text 1"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 2"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 3"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 4"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 5"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 6"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 7"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 8"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 9"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 10"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 11"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 12"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 13"));
list.add(new CustomRecycleViewAdapter.Data("Item Text 14"));
DialogX.globalStyle = MaterialStyle.style();
BottomDialog.build()
.setCustomView(new OnBindView<BottomDialog>(R.layout.layout_custom_recycleview) {
@Override
public void onBind(BottomDialog dialog, View v) {
RecyclerView recyclerView = (RecyclerView) v.findViewById(R.id.recycleView);
LinearLayoutManager layoutManager = new LinearLayoutManager(me);
recyclerView.setLayoutManager(layoutManager);
CustomRecycleViewAdapter adapter = new CustomRecycleViewAdapter(list);
recyclerView.setAdapter(adapter);
}
})
.show();
CustomDialog.show(new OnBindView<CustomDialog>(R.layout.layout_custom_dialog) {
@Override
public void onBind(final CustomDialog dialog, View v) {
ImageView btnOk = v.findViewById(R.id.btn_ok);
btnOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}
})
.setMaskColor(getResources().getColor(R.color.black30));
CustomDialog.show(new OnBindView<CustomDialog>(R.layout.layout_custom_dialog_align) {
private TextView btnSelectPositive;
@Override
public void onBind(final CustomDialog dialog, View v) {
btnSelectPositive = v.findViewById(R.id.btn_selectPositive);
btnSelectPositive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopTip.show("我知道了");
dialog.dismiss();
}
});
}
})
.setCancelable(false)
.setMaskColor(getResources().getColor(R.color.black30))
.setEnterAnimResId(R.anim.anim_custom_pop_enter)
.setExitAnimResId(R.anim.anim_custom_pop_exit)
.setAlignBaseViewGravity(view, Gravity.TOP) //显示在view上
.setBaseViewMarginBottom(-dip2px(45))
.show();
还有更多功能大家自己试验吧。
开源地址:https://github.com/kongzue/DialogX
我的Github:github.com/yutils
我的CSDN:https://blog.csdn.net/Yu1441
感谢关注微博:细雨若静
我的QQ:3373217 (可技术交流)