QMUI Android 的设计目的是用于辅助快速搭建一个具备基本设计还原效果的 Android 项目,同时利用自身提供的丰富控件及兼容处理,让开发者能专注于业务需求而无需耗费精力在基础代码的设计上。不管是新项目的创建,或是已有项目的维护,均可使开发效率和项目质量得到大幅度提升。
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//注释
//implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
//引用
implementation 'com.qmuiteam:qmui:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
框架的使用可以对照着QMUI官网上给出的一个Demo来写,下面分析一些常用的控件,逐步熟悉QMUI框架。
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)
.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(Dialog.this, "您的昵称: " + text, Toast.LENGTH_SHORT).show();
dialog.dismiss();
} else {
Toast.makeText(Dialog.this, "请填入昵称", Toast.LENGTH_SHORT).show();
}
}
})
.create(mCurrentDialogStyle).show();
}
}