QMUI_Android使用(一)QMUIDialog

1.QMUI_Android是腾讯出的一款UI框架,还有Web和IOS版本。 在AndriodStudio中新建一个Android项目,在APP中build.gradle的dependencies中加入compile'com.qmuiteam:qmui:1.0.6',如下:

QMUI_Android使用(一)QMUIDialog_第1张图片

2.在styles.xml文件中将主题改为<stylename="AppTheme"parent="QMUI.Compat">就可以使用了,当然可以在(value) 的形式来覆盖 QMUI 组件的默认表现。我的styles.xml如下:

<style name="AppTheme" parent="QMUI.Compat.NoActionBar">
    
    <item name="android:textAppearanceListItemSmall">@style/QDTextAppearanceListItemSmallitem>
    <item name="android:textAppearanceListItem">@style/QDtextAppearanceListItemitem>
    <item name="android:listPreferredItemHeight">?attr/qmui_list_item_height_higheritem>
    <item name="android:listPreferredItemHeightSmall">?attr/qmui_list_item_heightitem>

    <item name="colorPrimary">@color/colorPrimaryitem>
    <item name="colorPrimaryDark">@color/colorPrimaryDarkitem>
    
    <item name="colorAccent">@color/colorPrimaryitem>
    <item name="qmui_backgroundColor">@color/qmui_config_color_backgrounditem>
    <item name="android:actionBarSize">@dimen/qmui_dialog_action_button_radiusitem>
    <item name="actionBarSize">@dimen/activity_horizontal_marginitem>


    <item name="qmui_config_color_blue">@color/qmui_config_color_blueitem>
    <item name="qmui_config_color_red">@color/colorPrimaryDarkitem>
    <item name="qmui_config_color_background">@color/qmui_config_color_backgrounditem>

    
    <item name="qmui_alpha_pressed">?attr/qmui_config_color_blueitem>
    <item name="qmui_common_list_item_chevron">@drawable/qmui_list_item_bg_with_border_bottomitem>
    <item name="qmui_dialog_action_text_negative_color">@color/qmui_dialog_action_text_negative_coloritem>
    <item name="qmui_dialog_action_text_color">@color/qmui_config_color_blackitem>
    <item name="qmui_dialog_title_text_color">@color/qmui_config_color_blackitem>
    <item name="qmui_config_color_gray_4">@color/qmui_config_color_gray_4item>

style>
3.接下来就是使用了,在代码中引入包就可以直接使用了,这是一个带输入框的弹出框,QMUI的各种组件都比较简约美观,还有很多的类型的弹出框

QMUI_Android使用(一)QMUIDialog_第2张图片

final  QMUIDialog.EditTextDialogBuilder builder = new QMUIDialog.EditTextDialogBuilder(getActivity());
    builder.setTitle("灯泡ID输入")
            .setPlaceholder("请在此输入灯泡ID")
            .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();
        //获得出入的ID
        String ID = text.toString().trim();
        if (!ID.equals("")&&ID!=null&&CommonUtils.isInteger(ID)) {
            bulbID = Integer.parseInt(ID);
            if(bulbID>=0&&bulbID<=32767) {
                send_msg.setText(bulbID+"");
                dialog.dismiss();
            }else {
                Toast.makeText(getActivity(), "请填入合法灯泡ID", Toast.LENGTH_SHORT).show();
            }
        } else {
            Toast.makeText(getActivity(), "请填入合法灯泡ID", Toast.LENGTH_SHORT).show();
        }
    }
}).show();
删除警告弹出框

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();
具体的可以看官网的说明http://qmuiteam.com/android/page/document.html


你可能感兴趣的:(Android)