dialogx, recommend an open source Android pop-up window component.

Advantages of DialogX

Dialog is an important component for software to respond and give feedback to user operations, and DialogX will help developers quickly complete these tasks.

We strive to reduce what developers need to worry about, and create a dialog component that can be easily used at any time and in any situation.

On the premise of ease of use, DialogX provides more personalized interfaces for developers to expand, including inserting custom layouts in the dialog box, switching between light and dark mode, and even customizing a custom theme that is more in line with the App UI.

Open source address: https://github.com/kongzue/DialogX

✅Features of DialogX:

  1. DialogX adopts a new implementation method. The default View implementation method is lighter, and Window and DialogFragment implementation methods are also optional, free and flexible.
  2. The startup of DialogX has nothing to do with threads, you can start DialogX in any thread and it will automatically run in the UI thread.
  3. The startup of DialogX does not need the context parameter. By default, a static method is provided to start the dialog box with one line of code, which is more convenient to use.
    More freedom, developers can easily customize the style of any component in the dialog box, including text style, button text style, menu text style, input text style, as large as the title, as small as the prompt message can be modified as needed.
  4. DialogX adopts theme-separated design, comes with Material theme by default, and can optionally introduce other style themes such as IOS, Kongzue, MIUI, etc., which greatly reduces the size of the App. At the same time, it provides a theme interface. If there is a need for customization, you can implement a set of private themes yourself.
  5. Lower coupling, fewer problems, DialogX can close the Activity at will while the dialog box is running, without worrying about the WindowLeaked error that components such as AlertDialog used to cause.
  6. For a smoother experience, the animation effects of DialogX are richer. The dialog box startup animation is realized by non-linear animation, and it also has a coherent transition effect from waiting for prompts to completing error animations, making your APP more dynamic.
  7. All themes support two modes of bright and dark colors by default. You only need one-click configuration to switch between bright and dark color dialog themes, and more free layout content to meet customized needs. DialogX also supports automatic adaptation to the system. The system setting automatically judges the switching of the display effect of bright and dark colors.
  8. Easily realize the lifecycle control and immersive adaptation of dialog boxes.

introduce

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }      //增加 jitPack Maven 仓库
    }
}

1. Add in gradle

//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}"

2. Add in Application

DialogX.init(this)
DialogX.globalStyle = IOSStyle.style()

I give some examples of common usage


Message prompt box (click OK)

DialogX.globalStyle = IOSStyle.style();
MessageDialog.show("标题", "这里是正文内容。", "确定")
        .setOkButton(new OnDialogButtonClickListener<MessageDialog>() {
    
    
            @Override
            public boolean onClick(MessageDialog baseDialog, View v) {
    
    
                PopTip.show("点击确定按钮");
                return false;
            }
        });

insert image description here

selection dialog

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();

insert image description here

input box (text input)

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();
    }
});

insert image description here

Pop-up window (success/failure)

//正确
TipDialog.show(msg, WaitDialog.TYPE.SUCCESS)

//错误
TipDialog.show(msg, WaitDialog.TYPE.ERROR)

insert image description here

insert image description here

Message Prompt (Toast)

DialogX.globalStyle = MaterialStyle.style();
PopTip.show("这是一个提示");
PopTip.show(R.mipmap.img, "一个提示").setAutoTintIconInLightOrDarkMode(false).showLong();

insert image description here

Menu (choose one more)

//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;
            }
        }
    });

insert image description here
insert image description here

Bottom custom slide layout

<?xml version="1.0" encoding="utf-8"?>
<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();

insert image description here

custom dialog

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));

insert image description here

The dialog is displayed on the button

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();

insert image description here

There are more functions, please try it yourself.

Open source address: https://github.com/kongzue/DialogX

My Github: github.com/yutils
My CSDN: https://blog.csdn.net/Yu1441
Thanks for paying attention to Weibo: Ruojing in the rain
My QQ: 3373217 (Technical exchange available)

Guess you like

Origin blog.csdn.net/Yu1441/article/details/127069177