Skip to content
Kongzue edited this page Nov 16, 2023 · 1 revision

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

ℹ️ Frequently Asked Questions

Q: iOS theme style has no blur effect

A: Please check if you have configured renderscript support. For details, refer to the "Configuring DialogX" section on the Wiki homepage.

If already configured, but still ineffective, try changing the background of the Activity layout file to a solid color, not transparent or unset, such as white, and then try again.

If still ineffective, try downloading and running the Demo. If there is no blur effect, it means the device does not support renderscript, and you should choose another theme.


Q: The keyboard covers the dialog/input method does not push up the dialog

A: There are two solutions to choose from:

Solution 1: Optimize the software layout design

For vertical layouts, add a ScrollView component outside the layout.

The reason is that when the keyboard pops up, if there is a ScrollView in the Activity interface, the system will automatically compress the height of the ScrollView to ensure the interface is displayed reasonably. This can trigger a change in the height of the "bottom unsafe area," allowing DialogX to get the appropriate height for proper dialog display.

Solution 2: Directly use the input method processing mode: adjust the size of the interface.

Go to your project's AndroidManifest.xml and add configuration to the Activity:

<activity android:name=".MainActivity"
android:windowSoftInputMode="adjustResize"
...>
...
</activity>

Q: Dialog theme cannot be displayed in full screen

A: Please refer to the "Configuring DialogX" section on the Wiki homepage and check the theme settings of your Activity. Due to the implementation principle, DialogX dialogs cannot cover the native ActionBar area. It is recommended to use a theme with NoActionBar.

Additionally, if it cannot cover the navigation bar or is not fully displayed, try implementing immersion in your Activity and then try again. The BaseFramework framework is recommended for automatic implementation of immersion effects for the top status bar and bottom navigation bar (same as in the Demo).


Q: BottomDialog / BottomMenu / CustomDialog displays with extra top and bottom margins

A: As these components may involve immersive-related logic, DialogX automatically spaces out the screen's four "unsafe areas" to ensure normal component content display. However, this may cause extra margins in apps that have not implemented immersion. In this case, you can make your app's Activity immersive, including making the top status bar and bottom navigation bar background transparent, to perfectly solve the issue.

I recommend using the immersion solution of the BaseFramework framework (https://xiaozhuanlan.com/topic/4276819530)


Q: Full-screen dialog display turns the Activity background black

A: Please specify the background color of the Activity layout file.


Q: Dialog opens slowly, pressing the button does not open the dialog for a long time

A: Check if there are any issues with the main thread logic causing it to be blocked. The principle behind DialogX being able to start on an asynchronous thread is by posting the start message to the main thread to run. However, if there are blockages in the process of looping messages on the main thread, it will cause the smooth execution of DialogX's startup process to be hindered. It is recommended to run time-consuming operations on an asynchronous thread to minimize the main thread's workflow, and this issue will not occur.


Q: Dialog shows in the log but is not actually displayed on the interface

A: By default, DialogX dialogs do not require a context(activity) parameter to improve development efficiency. However, UI-dependent dialogs cannot be presented without a context parameter. Thus, DialogX listens to the startup of activities automatically after initialization and uses the current activity as the container to present and start the dialog. This covers 99% of development scenarios.

If you encounter a situation where the .show() command is executed, but the dialog does not appear as expected, it may be due to frequent activity switches or jumping to a newly started activity screen. In such cases, DialogX may not have received the correct activity callback and might display the dialog on the previous screen. To address this, please specify the activity parameter, such as .show(activity).

For WaitDialog, try WaitDialog.show(activity, "messageString") and specify when closing: WaitDialog.dismiss(activity).


Q: Dialog starts in another Activity

A: After executing the dialog's show command, switching to

another Activity, and finding the dialog displayed in a different Activity.

This issue is similar to the one above, caused by a blockage in the main thread. DialogX's startup requires waiting for the main thread to loop messages. If dismiss or show commands are frequently executed while processing transactions, or if there are frequent switches between Activities, it may lead to incorrect assessment of the Activity dependency for DialogX startup. In such cases, try specifying the Activity for the startup.

The method is to use the build() method of the dialog component to construct the dialog. Please note that the build() method has no parameters. You need to set other dialog parameters, such as title, content, buttons, etc., through methods, and finally execute the show(activity) method to start the dialog, as shown in the example below:

MessageDialog.build()
.setTitle("Title")
.setMessage("This is message content.")
.setOkButton("OK", new OnDialogButtonClickListener<MessageDialog>() {
   @Override
   public boolean onClick(MessageDialog baseDialog, View v) {
       //...
       return false;
   }
})
.show(MainActivity.this);	// Key point

Q: How to change the cursor color in the input box

A: You can use the InputInfo setting of InputDialog to modify it:

new InputDialog("Title", "Body content", "Confirm", "Cancel", "Text being entered")
  .setInputInfo(new InputInfo()
          .setCursorColor(Color.parseColor("#185ABD"))		// Set cursor color
          .setBottomLineColor(Color.parseColor("#185ABD"))	// Set bottom line color
  );

You can also use .setThemeColor(...) for a combined setting, but please note that in some theme styles, bottomLineColor may affect the background color of the input box.

Best compatibility solution:

Add the following code to your style for overwriting:

Define the AppCompat component theme color in DialogX for light mode:

<style name="DialogXCompatThemeLight" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorAccent">@color/colorAccent</item>
</style>

Define the AppCompat component theme color in DialogX for dark mode:

<style name="DialogXCompatThemeDark" parent="Theme.AppCompat.NoActionBar">
<item name="colorAccent">@color/colorAccent</item>
</style>

The input box in DialogX uses the system-native component, not a custom component, so the modification method needs to follow the native theme color modification scheme.


Q: After using DialogX, the interface appears to see through to the bottom navigation bar (small horizontal bar) behind the screen

A: Please disable this setting:

// Use immersive adaptation
// Please note, if you are not using immersive adaptation, disable this option, as it will affect whether the dialog layout can extend behind the navigation bar
DialogX.useActivityLayoutTranslationNavigationBar = false;

Detailed reason:

Since the fitSystemWindow flag can only be effective for one View under a Window, and DialogX cannot hook this flag, DialogX handles immersive-related tasks in the DialogXBaseRelativeLayout layout component, including keyboard pop-up, which are all related to changes in the height of the bottom unsafe area. However, Google, when dealing with cases where this Flag is not set, may cause old dialogs (already popped up) to receive an abnormal bottom height change value when a new dialog pops up. The characteristic is that it first returns to zero and then calls back a few times before returning to normal, manifesting as a "bounce" issue in dialogs involving bottom display.

To solve this issue, the latest version of DialogX by default enables the operation of setting the SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION flag on Window. If you need to turn it off, use:

DialogX.useActivityLayoutTranslationNavigationBar = false;

Q: DialogX cannot overlay on top of DialogFragment or AlertDialog

A: DialogX by default uses a View implementation, which can be understood as just adding a layer of DialogView on top of the current Activity. Because it's not a separate Window, it cannot overlay on top of DialogFragment or AlertDialog.

We recommend replacing dialogues implemented with DialogFragment or AlertDialog with DialogX instead. DialogX also offers components like CustomDialog to meet the needs for personalized dialogues.

If replacement is not feasible, you can try other implementation modes of DialogX, but use them cautiously. Other solutions still have bugs in certain situations. If you encounter any, please report them to us.


Q: Enable scroll inheritance in BottomDialog and FullScreenDialog dialogs for your scroll layout

A: Directly scrolling layouts like ScrollView, ListView, RecyclerView, etc., inside BottomDialog and FullScreenDialog may not achieve linkage with the dialog's downward closing motion. To implement this feature, please customize the corresponding components, inherit ScrollController, and complete the following interface implementations:

@Override
// Please follow the fixed writing style
public boolean isLockScroll() {
return lockScroll;
}

boolean lockScroll;

@Override
// Please follow the fixed writing style
public void lockScroll(boolean lockScroll) {
this.lockScroll=lockScroll;
}

@Override
public boolean onTouchEvent(MotionEvent event) {
if (lockScroll) return false;
return super.onTouchEvent(event);
}

@Override
// Get the scrolled distance, please note different components have different methods, adjust according to actual situations
public int getScrollDistance() {
return getScrollY();
}

@Override
// Fixed writing style
public boolean isCanScroll() {
return true;
}

Then, set the Tag "ScrollController" for the layout that needs scroll inheritance. BottomDialog and FullScreenDialog will recognize the ScrollController implementation in the sub-layouts during runtime and take over the touch event when it's scrolled to the top and continues to scroll down.


Q: Dialogs not intercepting back button or ineffective when popped up in Activity's onKeyDown

A: Since Activity's onKeyDown is upstream in the event chain, the dialog might not have started, or the KeyBack event has not been passed to the dialog yet, so the dialog cannot handle it. Please use onBackPressed for handling, for example:

@Override
public void onBackPressed() {
MessageDialog.show("Prompt", "Confirm exit?", "Yes", "No")
   .setOkButton(new OnDialogButtonClickListener<MessageDialog>() {
       @Override
       public boolean onClick(MessageDialog baseDialog, View v) {
           MainActivity.super.onBackPressed();
           return false;
       }
   });
}

Q: How to modify the corner radius? How to modify the background style of a component? How to modify the background style of a specific dialog?

A: You can use .setBackgroundRadius(float px) to set the corner radius size. After using this setting, the corners will clip the dialog content for display. Additionally, for BottomDialog, BottomMenu, FullScreenDialog, the corner radius setting only affects the top-left and top-right corners.

Also, refer to issues:228 for more information.


Q: How to implement a traditional progress bar dialog?

A: Please refer to Implementing a Traditional Progress Bar Dialog with DialogX

image


Q: How to reuse a dialog?

A: DialogX suggests using dialogs for single instances, meaning that when you execute the .dismiss() method on a dialog that has already been shown, it will be completely destroyed. This is to avoid memory usage and leaks. To reuse a dialog and retain its state (e.g., user input or operations in a custom layout).

If the main aim is to retain the content state of the custom layout, you can try retaining the custom layout:

// Retain customView
private View customView;

// Initialize the interface, e.g., in the onCreate method of the activity
customView = LayoutInflater.from(this).inflate(R.layout.layout_your_custom_view, null);

Then use this view as a parameter when starting the dialog:

CustomDialog.show(new OnBindView<CustomDialog>(customView) {
    @Override
    public void onBind(CustomDialog dialog, View v) {
      //...
    }
});

As long as customView is not recreated, its content will always be retained.

Alternatively, you can try not actually closing the dialog, but hiding it:

First, get the dialog instance when starting it:

// Set a global dialog instance
private InputDialog inputDialog;
// Display the dialog and get its instance
inputDialog = InputDialog.show("This is an input box","Input prompt text","OK","CANCEL")

Then write the related event handling:

inputDialog = InputDialog.show("This is an input box","Input prompt text","OK","CANCEL")
.setOkButton(new OnInputDialogButtonClickListener<InputDialog>() {
   @Override
   public boolean onClick(InputDialog dialog, View v, String inputStr) {
       // Use exit animation to hide the dialog
       dialog.hideWithExitAnim();
       // return true to intercept OK button click and not auto-dismiss
       return true;
   }
})
.setCancelButton(new OnInputDialogButtonClickListener<InputDialog>() {
   @Override
   public boolean onClick(InputDialog dialog, View v, String inputStr) {
       dialog.hideWithExitAnim();
       // return true to intercept Cancel button click and not auto-dismiss
       return true;
   }
})
.setOnBackgroundMaskClickListener(new OnBackgroundMaskClickListener<MessageDialog>() {
   @Override
   public boolean onClick(MessageDialog dialog, View v) {
       dialog.hideWithExitAnim();
       // return true to intercept background mask click and not auto-dismiss
       return true;
   }
})
.setOnBackPressedListener(new OnBackPressedListener<MessageDialog>() {
   @Override
   public boolean onBackPressed(MessageDialog dialog) {
       dialog.hideWithExitAnim();
       // return true to intercept back button click and not auto-dismiss
       return true;
   }
});

To redisplay this dialog, simply use the .show() command:

inputDialog.show();

Theoretically, DialogX will automatically destroy dialogs associated with an activity upon its destruction. If concerned, you can manually destroy it in activity#onDestroy():

inputDialog.dismiss();

Q: Text color and background color settings are ineffective?

Please check if the fontColor or backgroundColor values you set are correct. Generally, ColorInt values are needed. You can use Color.parseColor("#4D000000") to set a HEX color value, or use getResources().getColor(R.color.black30) to set a resource color value. Do not directly pass in the resource ID as it may not be effective.


ℹ️ Classic Issues

【Feature Suggestion】Can BottomMenu support displaying multiple lines instead of dots after exceeding 1 line? (issues:247)

If the view attached to popmenu is at the edge, the popmenu that pops up will be deformed (issues:231)

[The dialog on the current page shows up on the previous page

(issues:197)](https://github.com/kongzue/DialogX/issues/197)

Custom animation dialog flickers when closing (issues:280)

GuideDialog's display position is incorrect/shows up in the upper left corner of the screen (issues:304)

Clone this wiki locally