对话框QMUIDialog

消息类型对话框(蓝色按钮)


对话框QMUIDialog_第1张图片

实现:new QMUIDialog.MessageDialogBuilder(getActivity()) .setTitle("标题") .setMessage("确定要发送吗?") .addAction("取消", new QMUIDialogAction.ActionListener() { @Override public void onClick(QMUIDialog dialog, int index) { dialog.dismiss(); } }) .addAction("确定", new QMUIDialogAction.ActionListener() { @Override public void onClick(QMUIDialog dialog, int index) { dialog.dismiss(); Toast.makeText(getActivity(), "发送成功", Toast.LENGTH_SHORT).show(); } }) .show();

消息类型对话框(红色按钮)


对话框QMUIDialog_第2张图片

实现:new QMUIDialog.MessageDialogBuilder(getActivity())

.setTitle("标题")

.setMessage("确定要删除吗?")

.addAction("取消", new QMUIDialogAction.ActionListener() {

@Override

            public void onClick(QMUIDialog dialog, int index) {

dialog.dismiss();

            }

})

.addAction(0, "删除", QMUIDialogAction.ACTION_PROP_NEGATIVE, new QMUIDialogAction.ActionListener() {

@Override

            public void onClick(QMUIDialog dialog, int index) {

Toast.makeText(getActivity(), "删除成功", Toast.LENGTH_SHORT).show();

                dialog.dismiss();

            }

})

.show();


菜单类型对话框:


对话框QMUIDialog_第3张图片

实现:

final String[] items =new String[]{"选项1", "选项2", "选项3"};

new QMUIDialog.MenuDialogBuilder(getActivity())

.addItems(items, new DialogInterface.OnClickListener() {

@Override

            public void onClick(DialogInterface dialog, int which) {

Toast.makeText(getActivity(), "你选择了 " +items[which], Toast.LENGTH_SHORT).show();

                dialog.dismiss();

            }

})

.show();


带 Checkbox 的消息确认框:


对话框QMUIDialog_第4张图片

实现:new QMUIDialog.CheckBoxMessageDialogBuilder(getActivity())

.setTitle("退出后是否删除账号信息?")

.setMessage("删除账号信息").setChecked(true)

.addAction("取消", new QMUIDialogAction.ActionListener() {

@Override

            public void onClick(QMUIDialog dialog, int index) {

dialog.dismiss();

            }

})

.addAction("退出", new QMUIDialogAction.ActionListener() {

@Override

            public void onClick(QMUIDialog dialog, int index) {

dialog.dismiss();

            }

})

.show();


单选菜单类型对话框:


对话框QMUIDialog_第5张图片

实现:

final String[] items =new String[]{"选项1", "选项2", "选项3"};

final int checkedIndex =1;

new QMUIDialog.CheckableDialogBuilder(getActivity())

.setCheckedIndex(checkedIndex)

.addItems(items, new DialogInterface.OnClickListener() {

@Override

            public void onClick(DialogInterface dialog, int which) {

Toast.makeText(getActivity(), "你选择了 " +items[which], Toast.LENGTH_SHORT).show();

                dialog.dismiss();

            }

})

.show();


多选菜单类型对话框:


对话框QMUIDialog_第6张图片

final String[] items =new String[]{"选项1", "选项2", "选项3", "选项4", "选项5", "选项6"};

final QMUIDialog.MultiCheckableDialogBuilder builder =new QMUIDialog.MultiCheckableDialogBuilder(getActivity())

.setCheckedItems(new int[]{1, 3})

.addItems(items, new DialogInterface.OnClickListener() {

@Override

            public void onClick(DialogInterface dialog, int which) {

}

});

builder.addAction("取消", new QMUIDialogAction.ActionListener() {

@Override

    public void onClick(QMUIDialog dialog, int index) {

dialog.dismiss();

    }

});

builder.addAction("提交", new QMUIDialogAction.ActionListener() {

@Override

    public void onClick(QMUIDialog dialog, int index) {

String result ="你选择了 ";

        for (int i =0; i

result +="" +builder.getCheckedItemIndexes()[i] +"; ";

        }

Toast.makeText(getActivity(), result, Toast.LENGTH_SHORT).show();

        dialog.dismiss();

    }

});

builder.show();


多选菜单类型对话框(item 数量很多):


对话框QMUIDialog_第7张图片

final String[] items =new String[]{

"选项1", "选项2", "选项3", "选项4", "选项5", "选项6",

        "选项7", "选项8", "选项9", "选项10", "选项11", "选项12",

        "选项13", "选项14", "选项15", "选项16", "选项17", "选项18"

};

final QMUIDialog.MultiCheckableDialogBuilder builder =new QMUIDialog.MultiCheckableDialogBuilder(getActivity())

.setCheckedItems(new int[]{1, 3})

.addItems(items, new DialogInterface.OnClickListener() {

@Override

            public void onClick(DialogInterface dialog, int which) {

}

});

builder.addAction("取消", new QMUIDialogAction.ActionListener() {

@Override

    public void onClick(QMUIDialog dialog, int index) {

dialog.dismiss();

    }

});

builder.addAction("提交", new QMUIDialogAction.ActionListener() {

@Override

    public void onClick(QMUIDialog dialog, int index) {

String result ="你选择了 ";

        for (int i =0; i

result +="" +builder.getCheckedItemIndexes()[i] +"; ";

        }

Toast.makeText(getActivity(), result, Toast.LENGTH_SHORT).show();

        dialog.dismiss();

    }

});

builder.show();


带输入框的对话框:


对话框QMUIDialog_第8张图片

final QMUIDialog.EditTextDialogBuilder builder =new QMUIDialog.EditTextDialogBuilder(getActivity());

builder.setTitle("标题")

.setPlaceholder("在此输入您的昵称")

.setInputType(InputType.TYPE_CLASS_TEXT)

.addAction("取消", new QMUIDialogAction.ActionListener() {

@Override

            public void onClick(QMUIDialog dialog, int index) {

dialog.dismiss();

            }

})

.addAction("确定", new QMUIDialogAction.ActionListener() {

@Override

            public void onClick(QMUIDialog dialog, int index) {

CharSequence text =builder.getEditText().getText();

                if (text !=null && text.length() >0) {

Toast.makeText(getActivity(), "您的昵称: " + text, Toast.LENGTH_SHORT).show();

                    dialog.dismiss();

                }else {

Toast.makeText(getActivity(), "请填入昵称", Toast.LENGTH_SHORT).show();

                }

}

})

.show();


高度适应键盘升降的对话框:


对话框QMUIDialog_第9张图片

QMAutoTestDialogBuilder autoTestDialogBuilder = (QMAutoTestDialogBuilder)new QMAutoTestDialogBuilder(getActivity())

.addAction("取消", new QMUIDialogAction.ActionListener() {

@Override

            public void onClick(QMUIDialog dialog, int index) {

dialog.dismiss();

            }

})

.addAction("确定", new QMUIDialogAction.ActionListener() {

@Override

            public void onClick(QMUIDialog dialog, int index) {

Toast.makeText(getActivity(), "你点了确定", Toast.LENGTH_SHORT).show();

                dialog.dismiss();

            }

});

autoTestDialogBuilder.show();

QMUIKeyboardHelper.showKeyboard(autoTestDialogBuilder.getEditText(), true);

你可能感兴趣的:(对话框QMUIDialog)