Skip to content

FullScreenDialog_en

Kongzue edited this page Sep 14, 2024 · 7 revisions

🌐 View 简体中文文档 | 繁體中文文檔

📋 FullScreenDialog

Full Screen Dialog FullScreenDialog

FullScreenDialog provides a bottom-up dialog effect, similar to BottomDialog but with greater customization freedom compared to BottomDialog. FullScreenDialog does not offer any basic implementation, allowing developers to customize their layout. By default, it provides only a default sliding down close logic and the background dimming effect of the Activity.

Displaying a Full-Screen Dialog

First, prepare a layout file, then use the following code to display a full-screen dialog:

FullScreenDialog.show(new OnBindView<FullScreenDialog>(R.layout.layout_full_screen) {
    @Override
    public void onBind(FullScreenDialog dialog, View v) {
        //View childView = v.findViewById(resId)...
    }
});

Please note, DialogX's full-screen dialog does not come with title, body content, and button layouts; if needed, please implement them in your layout.

The full-screen dialog supports slide down to close by default, and cannot be closed by sliding down when cancelable is set to false.

If you are using ViewBinding, you can also replace it with OnBindingView to get the layout instance directly through binding:

FullScreenDialog.show(new OnBindingView<FullScreenDialog, LayoutCustomViewBinding>() {
            @Override
            public void onBind(FullScreenDialog dialog, View view, LayoutCustomViewBinding binding) {
                //View childView = binding.childView
            }
        });

Lifecycle Callbacks

To monitor the lifecycle of a dialog, you can implement the .setDialogLifecycleCallback(...) interface. It's recommended to use the build() method to construct the dialog:

FullScreenDialog.build()
        .setDialogLifecycleCallback(new DialogLifecycleCallback<FullScreenDialog>() {
            @Override
            public void onShow(FullScreenDialog dialog) {
                // Callback when the dialog is shown
            }
            @Override
            public void onDismiss(FullScreenDialog dialog) {
                // Callback when the dialog is dismissed
            }
        })
        .show();

FullScreenDialog also supports Lifecycle. You can get the Lifecycle object using .getLifecycle().

You can also handle lifecycle events by overriding them when creating an instance using new, for example:

// Event overriding demonstration
new FullScreenDialog() {
    @Override
    public void onShow(FullScreenDialog dialog) {
        //...
        tip("onShow");
    }
    @Override
    public void onDismiss(FullScreenDialog dialog) {
        //...
        tip("onDismiss");
    }
}

You can also use the methods .onShow(DialogXRunnable) and .onDismiss(DialogXRunnable) to handle lifecycle transactions, for example:

FullScreenDialog.show(...)
        .onShow(new DialogXRunnable<FullScreenDialog>() {
            @Override
            public void run(FullScreenDialog dialog) {
                //FullScreenDialog show!
            }
        })
        .onDismiss(new DialogXRunnable<FullScreenDialog>() {
            @Override
            public void run(FullScreenDialog dialog) {
                //FullScreenDialog dismiss!
            }
        });

Additional Methods

// Force refresh the interface
.refreshUI();

// Close the dialog
.dismiss();

// Allow clicking outside the area or back button to close
.setCancelable(boolean);
    
// Set back button callback
.setOnBackPressedListener(OnBackPressedListener);

// Get the instantiated dialog object, you can use this method for deeper customization of the Dialog's functionality
.getDialogImpl()

// Get custom layout instance
.getCustomView()
    
// Set background color, forcibly tint the dialog background, note that the parameter is an int type color value, not an R.color index
.setBackgroundColor(ColorInt);

// Set dialog corner radius (will clip the content display, this setting in FullScreenDialog only affects the top left and top right corners)
.setRadius(float px)

// Hide the dialog (without animation), to restore display execute the non-static method .show()
.hide();

// Hide the dialog (simulate closing dialog animation), to restore display execute the non-static method .show()
.hideWithExitAnim();

// Allow sliding down to close (only effective for Material theme)
.setAllowInterceptTouch(boolean)

// Check if it is currently showing
.isShow()

// Front dialog box display hierarchy
.bringToFront()

// Specify the level of dialog display
.setThisOrderIndex(int)

Background Mask

FullScreenDialog supports modifying the background mask to enrich extensibility. If you need a background mask, you can set it using the following code:

fullScreenDialog.setMaskColor(colorInt);

Please note, the input parameter is a ColorInt value, you can set a HEX color with Color.parseColor("#4D000000"), or set a color resource with getResources().getColor(R.color.black30).

Background Corner Radius

The background scaling of the full-screen dialog will default from the device's corners (if unable to retrieve, it defaults to the current value of 0, i.e., right angle) and will gradually transition to the activityContentRadius value while shrinking inwards. activityContentRadius defaults to the dialog's corner radius value, radius, which defaults to 15dp if not set.

You can specify a value for the target corner radius to which the full-screen dialog background will shrink:

.setActivityContentRadius(float) 

On devices that do not support this feature, specify a device corner radius size:

.setDeviceRadius(int)

activityContentRadius can also be set

to the standard setting: FullScreenDialog.ACTIVITY_CONTENT_RADIUS_KEEP. This setting will keep the background corner radius unchanged, shrinking according to the device corner radius.

Reducing Lag (Experimental)

FullScreenDialog dialog's background dimming principle involves taking a screenshot of the current display and scaling the screenshot. At this point, the interface theoretically does not need to render again. You can enable hiding and preventing the current Activity interface from being remeasured and rendered when FullScreenDialog is launched, which helps reduce lag when using complex layouts in FullScreenDialog:

ActivityScreenShotImageView.hideContentView = true;

When the dialog is closed, the interface will resume display and rendering.

Clone this wiki locally