效果:
对话框的使用,在demo里写不是很清楚,我拿出来做了一个小例子
dialog.xml布局文件是5个按钮,分别对应五种不同的对话框类型:
android:layout_width=“match_parent” android:layout_height=“match_parent” xmlns:app=“http://schemas.android.com/apk/res-auto”> android:id="@+id/d1" android:layout_width=“wrap_content” android:layout_height=“wrap_content” android:layout_centerInParent=“true” android:layout_alignParentTop=“true” android:padding=“20dp” app:qmui_radius=“22dp” app:qmui_borderWidth=“12px” app:qmui_borderColor="@color/colorPrimary" android:onClick=“showMessagePositiveDialog” android:text=“消息类型对话框(蓝色按钮)”/> android:id="@+id/d2" android:layout_width=“wrap_content” android:layout_height=“wrap_content” android:layout_centerInParent=“true” android:layout_below="@id/d1" android:padding=“20dp” app:qmui_radius=“22dp” app:qmui_borderWidth=“12px” app:qmui_borderColor="@color/colorPrimary" android:onClick=“showSingleChoiceDialog” android:text=“单选菜单类型对话框”/> android:id="@+id/d3" android:layout_width=“wrap_content” android:layout_height=“wrap_content” android:layout_centerInParent=“true” android:layout_below="@id/d2" android:padding=“20dp” app:qmui_radius=“22dp” app:qmui_borderWidth=“12px” app:qmui_borderColor="@color/colorPrimary" android:onClick=“showConfirmMessageDialog” android:text=“带 Checkbox 的消息确认框”/> android:id="@+id/d5" android:layout_width=“wrap_content” android:layout_height=“wrap_content” android:layout_centerInParent=“true” android:layout_below="@id/d3" android:padding=“20dp” app:qmui_radius=“22dp” app:qmui_borderWidth=“12px” app:qmui_borderColor="@color/colorPrimary" android:onClick=“showMultiChoiceDialog” android:text=“多选菜单类型对话框”/> android:id="@+id/d6" android:layout_width=“wrap_content” android:layout_height=“wrap_content” android:layout_centerInParent=“true” android:layout_below="@id/d5" android:padding=“20dp” app:qmui_radius=“22dp” app:qmui_borderWidth=“12px” app:qmui_borderColor="@color/colorPrimary" android:onClick=“showEditTextDialog” android:text=“带输入框的对话框”/> dialog.java文件: 一些属性的介绍: .setTitle(“消息类型对话框”):对话框标题 .setMessage(“蓝色按钮”):对话框内容 .addAction(“取消”, new QMUIDialogAction.ActionListener() 点击后的行为 dialog.dismiss() 对话框消失 .setChecked(true) 带check 选项 完整的代码贴出: 一些import: package com.example.win.qmuidemo; import android.content.DialogInterface; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.text.InputType; import android.view.LayoutInflater; import android.view.View; import android.widget.AdapterView; import android.widget.Button; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.Toast; import com.qmuiteam.qmui.util.QMUIStatusBarHelper; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Dialog extends AppCompatActivity { Button b1=null; Button b2=null; Button b3=null; Button b4=null; Button b5=null; Button b6=null; Button b7=null; private int mCurrentDialogStyle = com.qmuiteam.qmui.R.style.QMUI_Dialog; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dialog); } //消息类型对话框(蓝色按钮) public void showMessagePositiveDialog(View view) { new QMUIDialog.MessageDialogBuilder(this) .setTitle(“消息类型对话框”) .setMessage(“蓝色按钮”) .addAction(“取消”, new QMUIDialogAction.ActionListener() { @Override public void onClick(QMUIDialog dialog, int index) { dialog.dismiss(); Toast.makeText(Dialog.this, “点击了取消”, Toast.LENGTH_SHORT).show(); } }) .addAction(“确定”, new QMUIDialogAction.ActionListener() { @Override public void onClick(QMUIDialog dialog, int index) { dialog.dismiss(); Toast.makeText(Dialog.this, “点击了确定”, Toast.LENGTH_SHORT).show(); } }) .show(); } //单选菜单类型对话框 public void showSingleChoiceDialog(View view){ final String[] items = new String[]{“选项1”, “选项2”, “选项3”}; final int checkedIndex = 1; new QMUIDialog.CheckableDialogBuilder(this) .setCheckedIndex(checkedIndex) .addItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(Dialog.this, "你选择了 " + items[which], Toast.LENGTH_SHORT).show(); dialog.dismiss(); } }) .show(); } //带checkbox类型的对话框 public void showConfirmMessageDialog(View view){ new QMUIDialog.CheckBoxMessageDialogBuilder(this) .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(); } //多选菜单类型对话框 public void showMultiChoiceDialog(View view){ final String[] items = new String[]{“选项1”, “选项2”, “选项3”, “选项4”, “选项5”, “选项6”}; final QMUIDialog.MultiCheckableDialogBuilder builder = new QMUIDialog.MultiCheckableDialogBuilder(this) .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 < builder.getCheckedItemIndexes().length; i++) { result += “” + builder.getCheckedItemIndexes()[i] + "; "; } Toast.makeText(Dialog.this, result, Toast.LENGTH_SHORT).show(); dialog.dismiss(); } }); builder.show(); } //带输入框的对话框 public void showEditTextDialog(View view){ final QMUIDialog.EditTextDialogBuilder builder = new QMUIDialog.EditTextDialogBuilder(this); builder.setTitle(“标题”) .setPlaceholder(“在此输入您的昵称”) .setInputType(InputType.TYPE_CLASS_TEXT) 我这里整理了一份完整的学习思维以及Android开发知识大全PDF,有需要的同学可以自行领取。 资料获取方式:Android完整知识学习体系路线 当然实践出真知,即使有了学习线路也要注重实践,学习过的内容只有结合实操才算是真正的掌握。 View view){ final QMUIDialog.EditTextDialogBuilder builder = new QMUIDialog.EditTextDialogBuilder(this); builder.setTitle(“标题”) .setPlaceholder(“在此输入您的昵称”) .setInputType(InputType.TYPE_CLASS_TEXT) 我这里整理了一份完整的学习思维以及Android开发知识大全PDF,有需要的同学可以自行领取。 [外链图片转存中…(img-me3fGeCj-1645005173231)] 资料获取方式:Android完整知识学习体系路线 当然实践出真知,即使有了学习线路也要注重实践,学习过的内容只有结合实操才算是真正的掌握。
最后
最后