-
Notifications
You must be signed in to change notification settings - Fork 217
Home_en
Please choose one of the following two sources to import the project.
- In the project's build.gradle file, find the
allprojects{}
block and add the following code:
allprojects {
repositories {
google()
jcenter()
mavenCentral() // Add mavenCentral repository
}
}
- In the app's build.gradle file, find the
dependencies{}
block and add the following statement:
def dialogx_version = "0.0.49"
implementation "com.kongzue.dialogx:DialogX:${dialogx_version}"
- In the project's build.gradle file, find the
allprojects{}
block and add the following code:
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' } // Add jitPack Maven repository
}
}
- In the app's build.gradle file, find the
dependencies{}
block and add the following statement:
// Please replace dialogx_version with the latest version
def dialogx_version = "0.0.49"
implementation "com.github.kongzue.DialogX:DialogX:${dialogx_version}"
From version 0.0.43.beta8, the minimum API compatibility version has been lowered to 19. However, please note that some effects, such as icon tinting in the bottom menu dialog, cannot be used when it is lower than 21.
Beginners can refer to this article for instructions on how to integrate DialogX: 【Beginner Tutorial】Step-by-Step Guide to Integrate DialogX into Your Project
Before using DialogX, it must first be configured.
It is generally recommended to configure it in the onCreate method of the Application's implementation class:
// Initialization
DialogX.init(this);
Once configured, you can display dialog boxes.
To use the real-time blur effect of components (such as the IOS theme), you also need to find the android{defaultConfig{...}}
block in the app's build.gradle file and add the following configuration:
renderscriptTargetApi 21
renderscriptSupportModeEnabled true
For additional settings, refer to the following code:
// Enable debug mode, in some cases logs will be output using Log
DialogX.DEBUGMODE = true;
// Set theme style
DialogX.globalStyle = MaterialStyle.style();
// Set light/dark theme (effective when launching the next dialog)
DialogX.globalTheme = DialogX.THEME.LIGHT;
// Set the maximum width of the dialog box (in pixels)
DialogX.dialogMaxWidth = 1920;
// Set InputDialog to automatically pop up the keyboard
DialogX.autoShowInputKeyboard = true;
// Limit PopTip to display only one instance at a time (multiple PopTips can pop up simultaneously after closing)
DialogX.onlyOnePopTip = true;
// Set the default button text style for dialog boxes
DialogX.buttonTextInfo = (TextInfo);
// Set the default OK button text style for dialog boxes
DialogX.okButtonTextInfo = (TextInfo);
// Set the default title text style for dialog boxes
DialogX.titleTextInfo = (TextInfo);
// Set the default content text style for dialog boxes
DialogX.messageTextInfo = (TextInfo);
// Set the default text style for WaitDialog and TipDialog
DialogX.tipTextInfo = (TextInfo);
// Set the default text style for the input box
DialogX.inputInfo = (InputInfo);
// Set the default title text style for bottom menus and dialog boxes
DialogX.menuTitleInfo = (TextInfo);
// Set the default text style for bottom menus
DialogX.menuTextInfo = (TextInfo);
// Set the default background color for dialog boxes (value is ColorInt, -1 is ineffective)
DialogX.backgroundColor = Color.WHITE;
// Set whether the dialog box can be closed by clicking the outer mask area or the back button by default, this switch does not affect the tip box (TipDialog) and the waiting box (TipDialog)
DialogX.cancelable = true;
// Set whether the default tip box and waiting box (WaitDialog, TipDialog) can be closed
DialogX.cancelableTipDialog = false;
// Set the default text for the cancel button, affecting BottomDialog
DialogX.cancelButtonText = (CharSequence);
// Set the default text style for PopTip
DialogX.popTextInfo = (TextInfo);
// Set the global Dialog lifecycle listener
DialogX.dialogLifeCycleListener = (DialogLifecycleCallback);
// Set the light and dark style for TipDialog and WaitDialog, if not set, it will default according to globalTheme
DialogX.tipTheme = (THEME);
// Default background color for TipDialog and WaitDialog (value is ColorInt, -1 is ineffective)
DialogX.tipBackgroundColor = (ColorInt)
// Enable immersive adaptation
DialogX.enableImmersiveMode = true;
// ignore unsafe insets on left and right sides (to deal with the problem of margins on the left side of the dialog when some activities are displayed horizontally on devices with a bangs screen)
DialogX.ignoreUnsafeInsetsHorizontal = false;
/**
* Override the progress animation color of TipDialog and WaitDialog,
* Note that this property is of overriding nature, that is, setting this value will replace the original progress animation color of the tip box, including the color changes in the light and dark color switch
* (value is ColorInt, -1 is ineffective)
*/
DialogX.tipProgressColor = (ColorInt)
/**
* Set the navigation bar background color for BottomDialog
*/
DialogX.bottomDialogNavbarColor = Color.TRANSPARENT;
// Automatically execute on the main thread
DialogX.autoRunOnUIThread = true;
// Use haptic feedback (affects WaitDialog, TipDialog)
DialogX.useHaptic = true;
// Default message dialog title text
DialogX.defaultMessageDialogTitleText = (CharSequence);
// Default WaitDialog text
DialogX.defaultWaitDialogWaitingText = (CharSequence);
// Default text for success TipDialog
DialogX.defaultTipDialogSuccessText = (CharSequence);
// Default text of the error TipDialog
DialogX.defaultTipDialogErrorText = (CharSequence);
// Default text of the warning TipDialog
DialogX.defaultTipDialogWarningText = (CharSequence);
The theme style (DialogX.globalStyle) by default only comes with Material.style(). You can also import other themes. DialogX adopts a modular design, so you need to additionally import the theme package to use it.
View other themes here or see how to customize themes
Light and dark theme settings allow you to specify whether DialogX displays in light or dark effects. The meanings of the values are as follows:
Attribute | Explanation |
---|---|
LIGHT | 🌕 Force light mode |
DARK | 🌑 Force dark mode |
AUTO | 🌗 Automatic, changes based on the device's light and dark setting |
Please note, when using AUTO, and the dialog box has already started, if the user switches the system theme, the dialog box may restart (flicker). However, this will not lose the content and data of the dialog box. For example, if a user has entered a string of text in an InputDialog input box, this text will still be displayed in the input box after the dialog box restarts. If you have customized the layout of the dialog box, the state of these layouts will not change, but the dialog box lifecycle listener may reset, which means you may receive an additional onDismiss and onShow event trigger.
TextInfo is used to store basic text style settings, including a series of attributes and corresponding get/set methods. For example, the methods are explained as follows:
Attribute | Explanation | Default Value |
---|---|---|
fontSize | Font size, use default style when the value is -1, unit: dp | -1 |
gravity | Alignment, use default style when the value is -1, can use alignment methods like Gravity.CENTER
|
-1 |
fontColor | Text color, use default style when the value is 1, can obtain values using methods like Color.rgb(r,g,b) | 1 |
bold | Whether bold | false |
InputInfo is used to provide custom settings for input content, including a series of attributes and corresponding get/set methods. For example, the methods are explained as follows:
Attribute | Explanation | Default Value |
---|---|---|
MAX_LENGTH | Maximum length, -1 means no effect | -1 |
inputType | Custom input type, see android.text.InputType for types | |
textInfo | Default font style | (TextInfo) |
multipleLines | Support for multiple lines | false |
selectAllText | Default select all text (for easy modification) | false |
-keep class com.kongzue.dialogx.** { *; }
-dontwarn com.kongzue.dialogx.**
# Additionally, it's recommended to include android.view in the keep scope:
-keep class android.view.** { *; }
# If using blur effects, add the following configuration:
-dontwarn androidx.renderscript.**
-keep public class androidx.renderscript.** { *; }
DialogX depends on some other components to implement specific functionalities. Please check the following list to ensure your app has and meets the dependency requirements:
- androidx.appcompat component version 1.2.0 or above:
implementation 'androidx.appcompat:appcompat:1.2.0'
- Real-time blur effect of the iOS theme depends on RenderScript. If you want to use the blur effect, please refer to the Blur Effect section for configuration.
- Material You theme requires material component version 1.3.0 or above:
implementation 'com.google.android.material:material:1.3.0'
If you encounter some problems or don't achieve the expected effects, please try the following steps:
-
Download the Demo program from the DialogX main repository page and try running it. If it behaves abnormally on your device, please submit an Issue and specify the device model and system version. If it works normally, proceed to step 2.
-
Check the Common Issues to see if your issue has been explained and follow the suggestions.
-
If the above methods don't help, please submit an Issue explaining the problem and how to reproduce it, or you can join the group and discuss with me directly: 590498789
DialogX also provides many APIs to enrich usage and extend functionality. To learn about these APIs, please visit 《Advanced Extension Usage》.