Android Custom Control Series (5) - Universal Dialogue Box

Keywords: less Android

For reprinting, please indicate the source: http://blog.csdn.net/wangjihuanghun/article/details/57074535

Custom controls haven't been updated for some time. Today, they bring you a new dialog box style, in order to achieve richer functions with less code.

Because the dialog boxes have an impact on the user's operation, the dialog boxes on app are less used at present, but there are still some important information prompts that need to use the dialog box style, such as version updates, account landing in different places, and so on.

Let's look at the style of the custom dialog box:

There are two types of dialog boxes, which are quite common. All of the above background colors, text colors, and button clicks can be customized.

Here's how the four dialog boxes are implemented
Fig. 1:

DialogM.Builder builder = new DialogM.Builder(DialogMActivity.this)
        .setTitle("Discovery of new versions V5.4.1")
        .setContent("Version5.4.1\n[Update the default facial expression --- Synchronize the latest facial expression, chat is more interesting\n" +
                "[Data Card Upgrade --- New Visual Design to Increase the Source Information of Strangers\n" +
                "[Message Jump Optimization --- Mouse hovering over the message list does not move in order, no longer afraid of a mistake.\n" +
                "[Collection Preview Upgrade --- Perfecting the Image Browsing Experience and Optimizing the Web Preview Effect\n" +
                "[More Experience Optimization --- adjustable list width of group members; optimized weather location strategy; optimized picture viewer")
        .setStyle(DialogM.STYLE_TIP)
        .setPositiveButton("To update", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(DialogMActivity.this, "submit", Toast.LENGTH_SHORT).show();
                dialog.dismiss();
            }
        })
        .setNegativeButton("cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(DialogMActivity.this, "cancel", Toast.LENGTH_SHORT).show();
                dialog.dismiss();
            }
        });
builder.create().show();

Fig. 2:

DialogM.Builder builder = new DialogM.Builder(DialogMActivity.this)
        .setTitle("Hello")
        .setTitleBackColor(getResources().getColor(R.color.content))
        .setTitleTextColor(getResources().getColor(R.color.mainColor))
        .setAlertButtonBackColor(getResources().getColor(R.color.mainColor))
        .setAlertButtonTextColor(getResources().getColor(android.R.color.white))
        .setCanceledOnTouchOutside(false)
        .setAlertButton("Determine", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        })
        .setContent("landptf");
builder.create().show();

Fig. 3:

DialogM.Builder builder = new DialogM.Builder(DialogMActivity.this)
        .setContent("landptf")
        .setStyle(DialogM.STYLE_TIP)
        .setPositiveButton("submit", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(DialogMActivity.this, "submit", Toast.LENGTH_SHORT).show();
                dialog.dismiss();
            }
        })
        .setNegativeButton("cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(DialogMActivity.this, "cancel", Toast.LENGTH_SHORT).show();
                dialog.dismiss();
            }
        });
builder.create().show();

Fig. 4:

DialogM.Builder builder = new DialogM.Builder(DialogMActivity.this)
        .setAlertButton("", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        })
        .setContent("landptf");
builder.create().show();

Figures 3 and 4 use the default color entirely, and I specify red as the dominant color in the code.

All operations are called through the chain, and the color can be changed according to the style of your app. Of course, you can also download the code to add richer features.

Source code is relatively long, interested children's shoes can be click here See.
The builder mode is adopted in the source code, which can facilitate chain invocation and make the code look more concise.

Posted by sryder on Fri, 05 Apr 2019 18:18:30 -0700