### Example: Using Actions for Data Refresh in Dialogs Source: https://github.com/kongzue/dialogx/wiki/AdvancedExtendedUsage_tc Demonstrates how to use action penetration to refresh dialog content after an initial load or a user action (like clicking a button). This example shows defining action 1 to load data and executing it both on dialog show and after clicking the OK button. ```java MessageDialog.show("標題", "這裏是正文內容。", "確定") // Execute after dialog is shown... .onShow(new DialogXRunnable() { @Override public void run(MessageDialog dialog) { // Predefined action: Action 1 dialog.setActionRunnable(1, new DialogXRunnable() { @Override public void run(MessageDialog dialog) { tip("action 1 run!"); // Example: Load data via network to display in dialog } }); // Execute Action 1 dialog.runAction(1); } }) // Execute after clicking the button .setOkButton(new OnDialogButtonClickListener() { @Override public boolean onClick(MessageDialog dialog, View v) { PopTip.show("點擊確定按鈕"); // Example: Perform operations after clicking OK, then reload and execute Action 1 without closing the dialog // Penetrate and execute Action 1 dialog.runAction(1); return true; } }); ``` -------------------------------- ### Show Simple GuideDialog with Custom Image Source: https://github.com/kongzue/dialogx/wiki/GuideDialog_tc Use this to display a simple guide dialog with a custom image. The image can be a resource ID, Drawable, or Bitmap. ```java GuideDialog.show(R.mipmap.img_guide_tip); ``` -------------------------------- ### Show Simple PopTip Source: https://github.com/kongzue/dialogx/wiki/PopTip_tc Displays a basic text notification. No special setup is required beyond importing the PopTip class. ```java PopTip.show("這是一個提示"); ``` -------------------------------- ### BottomMenu Lifecycle Callback Example Source: https://github.com/kongzue/dialogx/wiki/BottomDialog&BottomMenu_tc Implement DialogLifecycleCallback to monitor dialog events like showing and dismissing. Use build() for dialog construction. ```java BottomMenu.build() .setDialogLifecycleCallback(new DialogLifecycleCallback() { @Override public void onShow(BottomMenu dialog) { //對話框啟動時回調 } @Override public void onDismiss(BottomMenu dialog) { //對話框關閉時回調 } }) .show(); ``` -------------------------------- ### Display PopNotification with Window Mode Source: https://github.com/kongzue/dialogx/wiki/PopNotification_tc Build and show a PopNotification. Crucially, set the DialogX.IMPL_MODE.WINDOW mode for the dialog to enable cross-interface display. This example also includes setting a title, icon, and a reply button that navigates to the main activity. ```java PopNotification.build() .setDialogImplMode(DialogX.IMPL_MODE.WINDOW) //重要,若全局使用 Window 實現模式則不需要設置 .setTitle("這是一條消息 " + notificationIndex) .setIcon(icon) .setButton("回復", new OnDialogButtonClickListener() { @Override public boolean onClick(PopNotification baseDialog, View v) { Intent intent = new Intent(me, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(intent); return false; } }) .showLong(); ``` -------------------------------- ### GuideDialog Utility Methods Source: https://github.com/kongzue/dialogx/wiki/引导对话框-GuideDialog Provides a collection of utility methods for managing GuideDialog instances, including UI refresh, dismissal, getting implementation details, and controlling visibility and layering. ```java //强制重新刷新界面 .refreshUI(); ``` ```java //关闭对话框 .dismiss(); ``` ```java //获取对话框实例化对象,您可以通过此方法更深度的定制Dialog的功能 .getDialogImpl() ``` ```java //获取自定义布局实例 .getCustomView() ``` ```java //设置对话框宽度 .setWidth(px) ``` ```java //设置对话框高度 .setHeight(px) ``` ```java //隐藏对话框(无动画),恢复显示请执行非静态方法的 .show() .hide(); ``` ```java //隐藏对话框(模拟关闭对话框的动画),恢复显示请执行非静态方法的 .show() .hideWithExitAnim(); ``` ```java //是否处于显示状态 .isShow() ``` ```java //置顶对话框 .bringToFront(); ``` ```java //指定对话框显示层级 .setThisOrderIndex(int) ``` -------------------------------- ### Show Simple GuideDialog with Custom Layout Source: https://github.com/kongzue/dialogx/wiki/GuideDialog_tc Use this to display a guide dialog with a custom layout. The OnBindView callback allows you to bind data and set listeners for views within the custom layout. ```java GuideDialog.show(new OnBindView(R.layout.layout_custom_dialog) { @Override public void onBind(final CustomDialog dialog, View v) { ImageView btnOk; btnOk = v.findViewById(R.id.btn_ok); btnOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); } }); ``` -------------------------------- ### Configure Guide Layout Alignment Source: https://github.com/kongzue/dialogx/wiki/引导对话框-GuideDialog When GuideDialog is bound to a view, you can control the position of the guide image/layout relative to the bound view using gravity flags. ```java //在启动方法指定 GuideDialog.show(btnFullScreenDialogLogin, R.mipmap.img_tip_login, Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL); //使用 set 方法指定 GuideDialog.build() .setAlignBaseViewGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL); ``` -------------------------------- ### Quick Tip Usage (Static Import) Source: https://github.com/kongzue/dialogx/wiki/PopTip_tc Shows how to use the `tip()` static method after importing it. ```APIDOC ## Quick Tip Usage (Static Import) ### Description Provides a shorthand for creating PopTips using the static `tip()` method after importing it. ### Methods - `tip(String message)` - `tip(String message, String okButtonText)` - `tip(int iconResId, String message)` - `tip(int iconResId, String message, String okButtonText)` ### Code Example ```java import static com.kongzue.dialogx.dialogs.PopTip.tip; // ... // Create a text tip tip(message); // Create a text tip with a button tip(message, okButtonText) .setButton(new OnDialogButtonClickListener() { @Override public boolean onClick(PopTip dialog, View v) { //... return false; } }); // Create a text tip with an icon tip(R.mipmap.icon, message); // Create a text tip with an icon and button tip(R.mipmap.icon, message, okButtonText); ``` ``` -------------------------------- ### Set Margin for Guide Layout Relative to Base View Source: https://github.com/kongzue/dialogx/wiki/引导对话框-GuideDialog Adjust the spacing between the guide image/layout and the base view it's anchored to. Margins can be set for all sides or individually, including negative values. ```java //指定引导图/布局和绑定布局之间的左上右下的间距(单位:像素) .setBaseViewMargin(left, top, right, bottom) .setBaseViewMargin(new int[]{left, top, right, bottom}) //仅单独指定上间距 .setBaseViewMarginTop(-dip2px(30)) ``` -------------------------------- ### Quick Tip Usage with Static Import Source: https://github.com/kongzue/dialogx/wiki/简单提示-PopTip Demonstrates using the static `tip` method for quick PopTip creation after importing it. This reduces boilerplate code. ```java import static com.kongzue.dialogx.dialogs.PopTip.tip; ``` ```java //创建一个文本提示 tip(message); //创建一个文本提示和一个按钮 tip(message, okButtonText) .setButton(new OnDialogButtonClickListener() { @Override public boolean onClick(PopTip dialog, View v) { //... return false; } }); //创建一个带图标的文字提示 tip(R.mipmap.icon, message); //创建一个带图标和按钮的文字提示 tip(R.mipmap.icon, message, okButtonText); ``` -------------------------------- ### Quick Tip Creation with Static Method Source: https://github.com/kongzue/dialogx/wiki/PopTip_tc Demonstrates various ways to create PopTips using the static 'tip' method after importing it. Supports text-only, text with button, and text with icon. ```java //創建一個文本提示 tip(message); //創建一個文本提示和一個按鈕 tip(message, okButtonText) .setButton(new OnDialogButtonClickListener() { @Override public boolean onClick(PopTip dialog, View v) { //... return false; } }); //創建一個帶圖示的文字提示 tip(R.mipmap.icon, message); //創建一個帶圖示和按鈕的文字提示 tip(R.mipmap.icon, message, okButtonText); ``` -------------------------------- ### Configure OK Button Text and Callback Source: https://github.com/kongzue/dialogx/wiki/基础对话框-MessageDialog-和-输入对话框-InputDialog Demonstrates various ways to configure the 'OK' button, including setting only the text, only the callback, or both text and callback. Setting the button to null hides it. ```java //只设置按钮文本 .setOkButton("确定") //只设置按钮点击回调 .setOkButton(new OnDialogButtonClickListener() { @Override public boolean onClick(MessageDialog baseDialog, View v) { toast("点击确定按钮"); return false; } }); //设置按钮文本并设置回调 .setOkButton("确定", new OnDialogButtonClickListener() { @Override public boolean onClick(MessageDialog baseDialog, View v) { toast("点击确定按钮"); return false; } }); //隐藏按钮 .setOkButton(null) ``` -------------------------------- ### Get Dialog Implementation Source: https://github.com/kongzue/dialogx/wiki/CustomDialog_tc Retrieve the dialog implementation object for deeper customization. ```java //獲取對話框實例化對象,您可以透過此方法更深度的訂製Dialog的功能 .getDialogImpl() ``` -------------------------------- ### 在 project build.gradle 中添加 MavenCentral 倉庫 Source: https://github.com/kongzue/dialogx/wiki/home_tc 在 project 的 build.gradle 文件中添加 mavenCentral 倉庫,以便引入 DialogX。 ```gradle allprojects { repositories { google() jcenter() mavenCentral() //增加 mavenCentral 倉庫 } } ``` -------------------------------- ### Get Custom View Instance Source: https://github.com/kongzue/dialogx/wiki/CustomDialog_tc Access the custom view instance associated with the dialog. ```java //獲取自訂布局實例 .getCustomView() ``` -------------------------------- ### Building PopTips with Custom Styles Source: https://github.com/kongzue/dialogx/wiki/PopTip_tc Demonstrates how to build a PopTip with a specific style, overriding global settings for a single instance. ```APIDOC ## Building PopTips with Custom Styles ### Description Allows for building a PopTip with a specific style, overriding global settings for a single instance. This is useful when you need a non-default theme for a particular dialog. ### Method Signature ```java PopTip.build() .setStyle(Style style) .setMessage(String message) .setButton(String buttonText) .show(); ``` ### Example ```java PopTip.build() // Or directly use .build(IOSStyle.style()) .setStyle(IOSStyle.style()) .setMessage("Message content.") .setButton("Button") .show(); ``` ``` -------------------------------- ### Get Custom View Instance Source: https://github.com/kongzue/dialogx/wiki/上下文菜单-PopMenu Access the instance of the custom layout previously set for the PopMenu. ```java .getCustomView() ``` -------------------------------- ### 单次设置实现模式为 Window Source: https://github.com/kongzue/dialogx/wiki/高阶扩展用法 仅在一个弹窗中设置 DialogX 的实现模式为 Window。必须使用 `.build()` 方法构建时指定。 ```java MessageDialog.build() //必须使用 build() 方法构建时指定 DialogImplMode 才会生效。 .setDialogImplMode(DialogX.IMPL_MODE.WINDOW) .setTitle("Title text") .setMessage("Message content") .setOkButton("OK") .show(); ``` -------------------------------- ### DialogV3 Dismiss Listener Example Source: https://github.com/kongzue/dialogx/wiki/从-DialogV3-迁移至-DialogX Demonstrates how to set an OnDismissListener for a TipDialog in DialogV3. This listener is called when the dialog is dismissed. ```java TipDialog.show(appCompatActivity, "登录成功", TipDialog.TYPE.SUCCESS).setOnDismissListener(new OnDismissListener() { @Override public void onDismiss() { } }); ``` -------------------------------- ### 在 app build.gradle 中添加 DialogX 依賴 (Jitpack) Source: https://github.com/kongzue/dialogx/wiki/home_tc 在 app 的 build.gradle 文件中添加 DialogX 的依賴,請確保替換為最新版本。 ```gradle //請將 dialogx_version 的值替換為最新版本 def dialogx_version = "0.0.49" implementation "com.github.kongzue.DialogX:DialogX:${dialogx_version}" ``` -------------------------------- ### Set Horizontal Button Order Source: https://github.com/kongzue/dialogx/wiki/自定义-DialogX-主题 Define the order of buttons when displayed horizontally. The example demonstrates using SPACE to create spacing between buttons. ```java @Override public int[] horizontalButtonOrder() { return new int[]{BUTTON_OK, BUTTON_OTHER, BUTTON_CANCEL}; } ``` ```java @Override public int[] horizontalButtonOrder() { return new int[]{BUTTON_OTHER, SPACE, BUTTON_CANCEL, BUTTON_OK}; } ``` -------------------------------- ### DialogX Methods for Button Configuration Source: https://github.com/kongzue/dialogx/wiki/BottomDialog&BottomMenu_en Demonstrates various ways to set button text, callbacks, or hide buttons using DialogX methods. ```java // Set only the button text .setOkButton("OK") // Set only the button click callback .setOkButton(new OnDialogButtonClickListener() { @Override public boolean onClick(BottomDialog dialog, View v) { toast("Clicked OK button"); return false; } }); // Set button text and callback .setOkButton("OK", new OnDialogButtonClickListener() { @Override public boolean onClick(BottomDialog dialog, View v) { toast("Clicked OK button"); return false; } }); // Hide the button .setOkButton(null) ``` -------------------------------- ### Displaying a PopTip with Icon and Button Source: https://github.com/kongzue/dialogx/wiki/PopTip_tc Illustrates how to show a PopTip with an icon, text, and a dismiss/action button. ```APIDOC ## Displaying a PopTip with Icon and Button ### Description Displays a notification with an icon, text, and a button for user interaction. ### Method `PopTip.show(int iconResId, String message, String buttonText)` ### Code Example ```java PopTip.show(R.mipmap.img_mail_line_white, "郵件已發送", "撤回"); ``` ``` -------------------------------- ### Display a Simple PopMenu Source: https://github.com/kongzue/dialogx/wiki/PopMenu_tc Shows how to display a basic PopMenu with a list of text options. ```APIDOC ## Display a Simple PopMenu ### Description Displays a PopMenu with the provided text options. ### Method `PopMenu.show(CharSequence... menus)` ### Parameters #### Path Parameters - **menus** (CharSequence...) - Required - The text for each menu item. ### Request Example ```java PopMenu.show("添加", "編輯", "刪除", "分享"); ``` ### Response #### Success Response (PopMenu Instance) Returns an instance of PopMenu for further configuration. ### Additional Notes - Menu content can also be set using `List`. - Icons can be set using `.setIconResIds()` or a callback. ``` -------------------------------- ### Override Pop Tip Settings (iOS) Source: https://github.com/kongzue/dialogx/wiki/CustomThemeStyle_tc Customize the appearance and behavior of PopTip components by overriding PopTipSettings. This example configures iOS-like layouts and animations. ```java public PopTipSettings popTipSettings() { return new PopTipSettings() { @Override public int layout(boolean light) { return light ? R.layout.layout_dialogx_poptip_ios : R.layout.layout_dialogx_poptip_ios_dark; } @Override public ALIGN align() { return ALIGN.TOP; } @Override public int enterAnimResId(boolean light) { return R.anim.anim_dialogx_ios_top_enter; } @Override public int exitAnimResId(boolean light) { return R.anim.anim_dialogx_ios_top_exit; } @Override public boolean tintIcon() { return false; } }; } ``` -------------------------------- ### 启用全局悬浮窗 Source: https://github.com/kongzue/dialogx/wiki/高阶扩展用法 在 Window 模式下,如果 app 具有悬浮窗权限,可以实现全局弹窗。需要在初始化时开启。 ```java DialogX.globalHoverWindow = true; ``` -------------------------------- ### Override Pop Notification Settings (iOS) Source: https://github.com/kongzue/dialogx/wiki/CustomThemeStyle_tc Customize PopNotification components with iOS-specific styles and animations by implementing PopNotificationSettings. This example sets the layout and animation resources. ```java public PopNotificationSettings popNotificationSettings() { return new PopNotificationSettings() { @Override public int layout(boolean light) { return light ? R.layout.layout_dialogx_popnotification_ios : R.layout.layout_dialogx_popnotification_ios_dark; } @Override public PopNotificationSettings.ALIGN align() { return ALIGN.TOP; } @Override public int enterAnimResId(boolean light) { return com.kongzue.dialogx.R.anim.anim_dialogx_notification_enter; } @Override public int exitAnimResId(boolean light) { return com.kongzue.dialogx.R.anim.anim_dialogx_notification_exit; } @Override public boolean tintIcon() { return false; } @Override ``` -------------------------------- ### Build Custom Dialog with Builder Source: https://github.com/kongzue/dialogx/wiki/自定义对话框-CustomDialog Constructs a custom dialog using the build() method, allowing for chaining of configuration options before showing. This is useful for more complex dialog setups. ```java CustomDialog.build() .setCustomView(new OnBindView(R.layout.layout_custom_dialog) { @Override public void onBind(final CustomDialog dialog, View v) { ImageView btnOk; btnOk = v.findViewById(R.id.btn_ok); btnOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); } }) .show(); ``` -------------------------------- ### Setting Icons for Menu Source: https://github.com/kongzue/dialogx/wiki/MessageDialog&InputDialog_tc Demonstrates three ways to set icons for menu items: directly via resource IDs, through a callback with logic based on menu text, and asynchronously loading network resources using Glide. ```APIDOC ## Setting Icons for Menu ### Description This section explains how to set icons for menu items in MessageDialog. You can specify icons directly using resource IDs, dynamically through a callback function based on menu text, or by asynchronously loading images from network URLs. ### Methods - `setIconResIds(int... resIds)`: Directly assigns resource IDs to menu icons. - `setOnIconChangeCallBack(OnIconChangeCallBack callBack)`: Sets a callback to dynamically determine icons based on menu item properties. - `setOnIconChangeCallBack(MenuIconAdapter adapter)`: Sets an adapter for asynchronous loading of icons, particularly from network sources. ### Examples **1. Using Resource IDs:** ```java .setIconResIds(R.mipmap.img_dialogx_demo_add, R.mipmap.img_dialogx_demo_delete, R.mipmap.img_dialogx_demo_edit) ``` **2. Using Callback:** ```java .setOnIconChangeCallBack(new OnIconChangeCallBack(true) { @Override public int getIcon(MessageMenu messageMenu, int index, String menuText) { switch (menuText) { case "添加": return R.mipmap.img_dialogx_demo_add; case "查看": return R.mipmap.img_dialogx_demo_view; case "編輯": return R.mipmap.img_dialogx_demo_edit; case "刪除": return R.mipmap.img_dialogx_demo_delete; } return 0; } }) ``` **3. Asynchronous Network Loading:** ```java .setOnIconChangeCallBack(new MenuIconAdapter(false) { String[] urls = { "http://www.kongzue.com/test/res/dialogx/ic_menu_add.png", "http://www.kongzue.com/test/res/dialogx/ic_menu_read_later.png", "http://www.kongzue.com/test/res/dialogx/ic_menu_link.png" }; @Override public boolean applyIcon(MessageMenu dialog, int index, String menuText, ImageView iconImageView) { Glide.with(MainActivity.this).load(urls[index]).into(iconImageView); return true; // true to display icon, false to hide } }); ``` ``` -------------------------------- ### Set Vertical Button Order with Splitters - Java Source: https://github.com/kongzue/dialogx/wiki/CustomThemeStyle_tc Override verticalButtonOrder to include SPLIT constants for visual separators between buttons in vertical layout. Refer to iOS theme for example. ```java @Override public int[] verticalButtonOrder() { return new int[]{BUTTON_OK, SPLIT, BUTTON_OTHER, SPLIT, BUTTON_CANCEL}; } ``` -------------------------------- ### Showing a Success Tip Dialog with Lifecycle Callback Source: https://github.com/kongzue/dialogx/wiki/从-DialogV3-迁移至-DialogX Demonstrates how to display a success tip dialog and attach a lifecycle callback to handle dismissal. The callback uses generics to automatically infer the dialog type. ```java TipDialog.show("登录成功", TipDialog.TYPE.SUCCESS).setDialogLifecycleCallback( new DialogLifecycleCallback() { @Override public void onDismiss(WaitDialog dialog) { } }); ``` -------------------------------- ### Implement BottomMenu Lifecycle Callbacks Source: https://github.com/kongzue/dialogx/wiki/底部对话框-BottomDialog-和底部菜单-BottomMenu Use build() to construct a BottomMenu and set a DialogLifecycleCallback to monitor its show and dismiss events. ```java BottomMenu.build() .setDialogLifecycleCallback(new DialogLifecycleCallback() { @Override public void onShow(BottomMenu dialog) { //对话框启动时回调 } @Override public void onDismiss(BottomMenu dialog) { //对话框关闭时回调 } }) .show(); ``` -------------------------------- ### Get User Button Selection Result Source: https://github.com/kongzue/dialogx/wiki/基础对话框-MessageDialog-和-输入对话框-InputDialog Allows retrieving the user's button selection after a MessageDialog has been displayed and potentially dismissed. The result is an enum indicating which button was pressed. ```java private MessageDialog dialog; //业务流程模拟,创建并显示了一个对话框,但不立即处理点击事务 dialog = MessageDialog.show("Title", "Ask Question", "OK", "NO", "OTHER"); //需要时可根据 getButtonSelectResult() 方法获取用户点击了哪个按钮选项 BUTTON_SELECT_RESULT result = dialog.getButtonSelectResult(); ``` -------------------------------- ### Setting Menu Items and Icons Source: https://github.com/kongzue/dialogx/wiki/BottomDialog&BottomMenu_en Configure the menu items and their corresponding icons for a bottom menu. Use string arrays for items and resource IDs for icons. ```java .setMenus("Add", "Edit", "Delete", "Share"...); .setIconResIds(R.mipmap.img_dialogx_demo_add, R.mipmap.img_dialogx_demo_edit...); ``` -------------------------------- ### Disable Cordova SplashScreen Source: https://github.com/kongzue/dialogx/wiki/【疑难问题】WebView-在加载完成前调用-DialogX-弹窗导致页面卡住、不显示弹窗 Comment out the splash screen setup in CordovaActivity.init() to prevent it from blocking WebView loading. Use with caution as it may disrupt Cordova's startup flow. ```java cordovaInterface.pluginManager.postMessage("setupSplashScreen", splashScreen); ``` -------------------------------- ### Displaying TipDialog with Different Types Source: https://github.com/kongzue/dialogx/wiki/等待框-WaitDialog-和提示框-TipDialog Illustrates how to show TipDialogs for warning and error states. ```APIDOC ## Displaying TipDialog with Different Types ### Description Demonstrates the usage of TipDialog for displaying warning and error messages. ### Method ```java TipDialog.show(String message, WaitDialog.TYPE type) ``` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```java // Warning TipDialog.show("Warning!", WaitDialog.TYPE.WARNING); // Error TipDialog.show("Error!", WaitDialog.TYPE.ERROR); ``` ### Response #### Success Response - None (Dialog is displayed on the UI) #### Response Example - None ``` -------------------------------- ### Show Dialog List with Queue - Java Source: https://github.com/kongzue/dialogx/wiki/AdvancedExtendedUsage_tc Use `DialogX.showDialogList(...)` to display multiple dialogs sequentially. Ensure dialogs are built with `.build()` and not shown manually. Call `.cleanDialogList()` to stop the queue. ```java DialogX.showDialogList( MessageDialog.build().setTitle("提示").setMessage("這是一組消息對話框隊列").setOkButton("開始").setCancelButton("取消") .setCancelButton(new OnDialogButtonClickListener() { @Override public boolean onClick(MessageDialog dialog, View v) { dialog.cleanDialogList(); return false; } }), PopTip.build().setMessage("每個對話框會依次顯示"), PopNotification.build().setTitle("通知提示").setMessage("直到上一個對話框消失"), InputDialog.build().setTitle("請注意").setMessage("你必須使用 .build() 方法構建,並保證不要自己執行 .show() 方法").setInputText("輸入文字").setOkButton("知道了"), TipDialog.build().setMessageContent("準備結束...").setTipType(WaitDialog.TYPE.SUCCESS), BottomDialog.build().setTitle("結束").setMessage("下滑以結束旅程,祝你編碼愉快!").setCustomView(new OnBindView(R.layout.layout_custom_dialog) { @Override public void onBind(BottomDialog dialog, View v) { ImageView btnOk; btnOk = v.findViewById(R.id.btn_ok); btnOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); } }) ); ``` -------------------------------- ### Configure GuideDialog Alignment and Margins Source: https://github.com/kongzue/dialogx/wiki/GuideDialog_tc Control the position of the guide image/layout relative to the bound view using gravity and margins. This allows precise placement around the target UI element. ```java //在啟動方法指定 GuideDialog.show(btnFullScreenDialogLogin, R.mipmap.img_tip_login, Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL); //使用 set 方法指定 GuideDialog.build() .setAlignBaseViewGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL); //指定引導圖/布局和綁定布局之間的左上右下的間距(單位:像素) .setBaseViewMargin(left, top, right, bottom) .setBaseViewMargin(new int[]{left, top, right, bottom}) //僅單獨指定上間距 .setBaseViewMarginTop(-dip2px(30)) ``` -------------------------------- ### Getting User Selection Status from BottomDialog Source: https://github.com/kongzue/dialogx/wiki/BottomDialog&BottomMenu_en Obtain the user's button selection result from a dialog handle after it has been displayed. Useful for handling business logic that depends on user interaction. ```java private BottomDialog dialog; // Business process simulation, creating and displaying a dialog but not immediately processing the click events dialog = BottomDialog.show(...); // When needed, you can get which button option the user clicked using the getButtonSelectResult() method BUTTON_SELECT_RESULT result = dialog.getButtonSelectResult(); ``` -------------------------------- ### Displaying a PopTip with Icon Source: https://github.com/kongzue/dialogx/wiki/PopTip_tc Demonstrates how to display a PopTip with an accompanying icon. ```APIDOC ## Displaying a PopTip with Icon ### Description Displays a notification with a specified icon and text. ### Method `PopTip.show(int iconResId, String message)` ### Code Example ```java PopTip.show(R.mipmap.img_mail_line_white, "收到一封郵件"); ``` ``` -------------------------------- ### Import Static Tip Method Source: https://github.com/kongzue/dialogx/wiki/PopTip_tc Imports the static 'tip' method for concise PopTip creation. This can often be auto-generated by IDEs. ```java import static com.kongzue.dialogx.dialogs.PopTip.tip; ``` -------------------------------- ### Set Icons for PopMenu Items Source: https://github.com/kongzue/dialogx/wiki/PopMenu_tc Demonstrates how to set icons for menu items, including options for tinting and asynchronous loading. ```APIDOC ## Set Icons for PopMenu Items ### Description Allows setting icons for menu items, with options for direct resource IDs, callback-based setting, and asynchronous loading. ### Method `.setIconResIds(int... iconResIds)` ### Parameters #### Path Parameters - **iconResIds** (int...) - Required - Resource IDs for the icons. Use 0 for items without icons. ### Request Example ```java .setIconResIds(R.mipmap.img_dialogx_demo_add, R.mipmap.img_dialogx_demo_edit) ``` ### Method `.setAutoTintIconInLightOrDarkMode(boolean)` ### Parameters #### Path Parameters - **autoTint** (boolean) - Required - Whether to tint icons based on light/dark mode. ### Request Example ```java .setAutoTintIconInLightOrDarkMode(true) ``` ### Method `.setOnIconChangeCallBack(OnIconChangeCallBack callback)` ### Parameters #### Path Parameters - **callback** (OnIconChangeCallBack) - Required - Callback to dynamically provide icons. ### Request Example ```java .setOnIconChangeCallBack(new OnIconChangeCallBack(true) { @Override public int getIcon(PopMenu dialog, int index, String menuText) { // Return icon resource ID or 0 return R.mipmap.ic_launcher; } }); ``` ### Method `.setOnIconChangeCallBack(MenuIconAdapter adapter)` ### Parameters #### Path Parameters - **adapter** (MenuIconAdapter) - Required - Adapter for asynchronous icon loading. ### Request Example ```java .setOnIconChangeCallBack(new MenuIconAdapter(false) { @Override public boolean applyIcon(PopMenu dialog, int index, String menuText, ImageView iconImageView) { // Load icon asynchronously into iconImageView // Glide.with(context).load(url).into(iconImageView); return true; // Return true if icon is applied, false to hide } }); ``` ``` -------------------------------- ### Customizing Bottom Dialog Style with iOS Theme Source: https://github.com/kongzue/dialogx/wiki/CustomThemeStyle_tc Implement overrideBottomDialogRes() to customize bottom dialog styles. Returning null uses default Material theme. This example configures an iOS-like appearance. ```java @Override public BottomDialogRes overrideBottomDialogRes() { return new BottomDialogRes() { @Override public boolean touchSlide() { return false; } @Override public int overrideDialogLayout(boolean light) { return light ? R.layout.layout_dialogx_bottom_ios : R.layout.layout_dialogx_bottom_ios_dark; } @Override public int overrideMenuDividerDrawableRes(boolean light) { return light ? R.drawable.rect_dialogx_ios_menu_split_divider : R.drawable.rect_dialogx_ios_menu_split_divider_night; } @Override public int overrideMenuDividerHeight(boolean light) { return 1; } @Override public int overrideMenuTextColor(boolean light) { return light ? R.color.dialogxIOSBlue : R.color.dialogxIOSBlueDark; } @Override public float overrideBottomDialogMaxHeight() { return 0f; } @Override public int overrideMenuItemLayout(boolean light, int index, int count, boolean isContentVisibility) { if (light) { if (index == 0) { return isContentVisibility ? R.layout.item_dialogx_ios_bottom_menu_center_light : R.layout.item_dialogx_ios_bottom_menu_top_light; } else if (index == count - 1) { return R.layout.item_dialogx_ios_bottom_menu_bottom_light; } else { return R.layout.item_dialogx_ios_bottom_menu_center_light; } } else { if (index == 0) { return isContentVisibility ? R.layout.item_dialogx_ios_bottom_menu_center_dark : R.layout.item_dialogx_ios_bottom_menu_top_dark; } else if (index == count - 1) { return R.layout.item_dialogx_ios_bottom_menu_bottom_dark; } else { return R.layout.item_dialogx_ios_bottom_menu_center_dark; } } } @Override public int overrideSelectionMenuBackgroundColor(boolean light) { return 0; } @Override public boolean selectionImageTint(boolean light) { return true; } @Override public int overrideSelectionImage(boolean light, boolean isSelected) { return 0; } }; } ``` -------------------------------- ### 构建和显示队列对话框 Source: https://github.com/kongzue/dialogx/wiki/高阶扩展用法 使用 `DialogX.showDialogList` 构建多个对话框,它们将按顺序显示。对话框必须使用 `.build()` 方法构建且未执行 `.show()`。使用 `.cleanDialogList()` 可停止队列。 ```java DialogX.showDialogList( MessageDialog.build().setTitle("提示").setMessage("这是一组消息对话框队列").setOkButton("开始").setCancelButton("取消") .setCancelButton(new OnDialogButtonClickListener() { @Override public boolean onClick(MessageDialog dialog, View v) { dialog.cleanDialogList(); return false; } }), PopTip.build().setMessage("每个对话框会依次显示"), PopNotification.build().setTitle("通知提示").setMessage("直到上一个对话框消失"), InputDialog.build().setTitle("请注意").setMessage("你必须使用 .build() 方法构建,并保证不要自己执行 .show() 方法").setInputText("输入文字").setOkButton("知道了"), TipDialog.build().setMessageContent("准备结束...").setTipType(WaitDialog.TYPE.SUCCESS), BottomDialog.build().setTitle("结束").setMessage("下滑以结束旅程,祝你编码愉快!").setCustomView(new OnBindView(R.layout.layout_custom_dialog) { @Override public void onBind(BottomDialog dialog, View v) { ImageView btnOk; btnOk = v.findViewById(R.id.btn_ok); btnOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); } }) ); ``` -------------------------------- ### Set Horizontal Button Order with Space - Java Source: https://github.com/kongzue/dialogx/wiki/CustomThemeStyle_tc Override horizontalButtonOrder to use SPACE constants for spacing between buttons in horizontal layout, as seen in Material themes. Refer to Material theme example. ```java @Override public int[] horizontalButtonOrder() { return new int[]{BUTTON_OTHER, SPACE, BUTTON_CANCEL, BUTTON_OK}; } ``` -------------------------------- ### Asynchronously Load PopMenu Icons Source: https://github.com/kongzue/dialogx/wiki/PopMenu_tc Load menu icons asynchronously using `MenuIconAdapter`. The `applyIcon` method receives the `ImageView` for the icon and should return `true` to display it, `false` to hide it. This example uses Glide for loading. ```java .setOnIconChangeCallBack(new MenuIconAdapter(false) { String[] urls = { "http://www.kongzue.com/test/res/dialogx/ic_menu_add.png", "http://www.kongzue.com/test/res/dialogx/ic_menu_read_later.png", "http://www.kongzue.com/test/res/dialogx/ic_menu_link.png" }; @Override public boolean applyIcon(PopMenu dialog, int index, String menuText, ImageView iconImageView) { Glide.with(MainActivity.this).load(urls[index]).into(iconImageView); //演示通過 Glide 加載網絡資源到菜單圖標中 return true; } }); ``` -------------------------------- ### Build PopTip with Custom Style Source: https://github.com/kongzue/dialogx/wiki/PopTip_tc Construct a PopTip instance using the builder pattern and apply a specific style, such as IOSStyle, before displaying it. ```java PopTip.build() //或直接使用 .build(IOSStyle.style()) .setStyle(IOSStyle.style()) .setMessage("Message content.") .setButton("Button") .show(); ``` -------------------------------- ### Override Bottom Dialog Styles (iOS) Source: https://github.com/kongzue/dialogx/wiki/CustomThemeStyle_tc Implement custom styles for bottom dialogs by overriding methods in BottomDialogRes. This example shows how to set iOS-specific layouts, dividers, text colors, and menu item layouts. ```java public BottomDialogRes overrideBottomDialogRes() { return new BottomDialogRes() { @Override public boolean touchSlide() { return false; } @Override public int overrideDialogLayout(boolean light) { //return light ? R.layout.layout_dialogx_bottom_material : R.layout.layout_dialogx_bottom_material_dark; return light ? R.layout.layout_dialogx_bottom_ios : R.layout.layout_dialogx_bottom_ios_dark; } @Override public int overrideMenuDividerDrawableRes(boolean light) { return light ? R.drawable.rect_dialogx_ios_menu_split_divider : R.drawable.rect_dialogx_ios_menu_split_divider_night; } @Override public int overrideMenuDividerHeight(boolean light) { return 1; } @Override public int overrideMenuTextColor(boolean light) { return light ? R.color.dialogxIOSBlue : R.color.dialogxIOSBlueDark; } @Override public float overrideBottomDialogMaxHeight() { return 0f; } @Override public int overrideMenuItemLayout(boolean light, int index, int count, boolean isContentVisibility) { if (light) { if (index == 0) { return isContentVisibility ? R.layout.item_dialogx_ios_bottom_menu_center_light : R.layout.item_dialogx_ios_bottom_menu_top_light; } else if (index == count - 1) { return R.layout.item_dialogx_ios_bottom_menu_bottom_light; } else { return R.layout.item_dialogx_ios_bottom_menu_center_light; } } else { if (index == 0) { return isContentVisibility ? R.layout.item_dialogx_ios_bottom_menu_center_dark : R.layout.item_dialogx_ios_bottom_menu_top_dark; } else if (index == count - 1) { return R.layout.item_dialogx_ios_bottom_menu_bottom_dark; } else { return R.layout.item_dialogx_ios_bottom_menu_center_dark; } } } @Override public int overrideSelectionMenuBackgroundColor(boolean light) { return 0; } @Override public boolean selectionImageTint(boolean light) { return true; } @Override public int overrideSelectionImage(boolean light, boolean isSelected) { return 0; } @Override public int overrideMultiSelectionImage(boolean light, boolean isSelected) { return 0; } }; } ``` -------------------------------- ### Handle Back Press with MessageDialog in DialogX Source: https://github.com/kongzue/dialogx/wiki/常见问题 Use onBackPressed to handle back presses within DialogX, as Activity's onKeyDown may not intercept events before the dialog is ready. This example shows how to display a confirmation dialog before exiting. ```java @Override public void onBackPressed() { MessageDialog.show("提示", "确认退出?", "是", "否") .setOkButton(new OnDialogButtonClickListener() { @Override public boolean onClick(MessageDialog baseDialog, View v) { MainActivity.super.onBackPressed(); return false; } }); } ``` -------------------------------- ### Implement Custom iOS PopTip Style Source: https://github.com/kongzue/dialogx/wiki/CustomThemeStyle_tc Implement custom layout, alignment, and animation resources for iOS-style PopTips. Returns null to use default styles. ```java @Override public PopTipSettings popTipSettings() { return new PopTipSettings() { @Override public int layout(boolean light) { return light?R.layout.layout_dialogx_poptip_ios :R.layout.layout_dialogx_poptip_ios_dark; } @Override public ALIGN align() { return ALIGN.TOP; } @Override public int enterAnimResId(boolean light) { return R.anim.anim_dialogx_ios_top_enter; } @Override public int exitAnimResId(boolean light) { return R.anim.anim_dialogx_ios_top_exit; } }; } ``` -------------------------------- ### Using Lifecycle Listeners with DialogXRunnable Source: https://github.com/kongzue/dialogx/wiki/等待框-WaitDialog-和提示框-TipDialog Demonstrates an alternative way to handle dialog show and dismiss events using DialogXRunnable. ```APIDOC ## Using Lifecycle Listeners with DialogXRunnable ### Description Provides an alternative method for handling dialog show and dismiss events using the `DialogXRunnable` interface. ### Method ```java Dialog.onShow(DialogXRunnable runnable) Dialog.onDismiss(DialogXRunnable runnable) ``` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```java WaitDialog.show("please wait...") .onShow(new DialogXRunnable() { @Override public void run(WaitDialog dialog) { // WaitDialog show! } }) .onDismiss(new DialogXRunnable() { @Override public void run(WaitDialog dialog) { // WaitDialog dismiss! } }); ``` ### Response #### Success Response - None (Lifecycle events are handled) #### Response Example - None ``` -------------------------------- ### Displaying a Simple PopTip Source: https://github.com/kongzue/dialogx/wiki/PopTip_tc Shows how to display a basic text PopTip. ```APIDOC ## Displaying a Simple PopTip ### Description Displays a basic text notification. ### Method `PopTip.show(String message)` ### Code Example ```java PopTip.show("這是一個提示"); ``` ``` -------------------------------- ### Display Simple PopMenu Source: https://github.com/kongzue/dialogx/wiki/PopMenu_tc Use this to show a basic PopMenu with a list of text options. It can also accept a List for menu content. ```java PopMenu.show("添加", "編輯", "刪除", "分享"); ``` -------------------------------- ### Use DialogXRunnable for Lifecycle Events Source: https://github.com/kongzue/dialogx/wiki/PopTip_tc Shows how to use DialogXRunnable for concise handling of 'onShow' and 'onDismiss' lifecycle events directly on a PopTip instance. ```java PopTip.show(...) .onShow(new DialogXRunnable() { @Override public void run(PopTip dialog) { //PopTip show! } }) .onDismiss(new DialogXRunnable() { @Override public void run(PopTip dialog) { //PopTip dismiss! } }); ``` -------------------------------- ### Show Simple PopMenu Source: https://github.com/kongzue/dialogx/wiki/上下文菜单-PopMenu Displays a basic PopMenu with provided text options. Can also accept a List for menu content. ```java PopMenu.show("添加", "编辑", "删除", "分享"); ``` -------------------------------- ### Using Custom Layouts Source: https://github.com/kongzue/dialogx/wiki/等待框-WaitDialog-和提示框-TipDialog Explains how to apply a custom layout to WaitDialog and TipDialog for a personalized appearance. ```APIDOC ## Using Custom Layouts ### Description Enables the use of custom layout files for WaitDialog and TipDialog to achieve a unique visual style. When a custom layout is applied, the default animations are hidden. ### Method ```java Dialog.setCustomView(OnBindView viewBinder) ``` ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```java WaitDialog.show("Please Wait!").setCustomView(new OnBindView(R.layout.layout_custom_view) { @Override public void onBind(WaitDialog dialog, View v) { // Custom view binding logic } }); ``` ### Response #### Success Response - None (Dialog uses the custom layout) #### Response Example - None ``` -------------------------------- ### Add Maven Repository to settings.gradle Source: https://github.com/kongzue/dialogx/wiki/【新手教程】手把手教你如何引入DialogX到自己的项目里使用 Configure your project's settings.gradle file to include the JitPack repository, which hosts the DialogX library. Sync your project after adding this. ```gradle maven { url 'https://jitpack.io' } ``` -------------------------------- ### Build PopMenu with Lifecycle Callbacks Source: https://github.com/kongzue/dialogx/wiki/PopMenu_tc Construct a PopMenu using the `build()` method and attach lifecycle callbacks using `setDialogLifecycleCallback`. This allows monitoring of show and dismiss events. ```java PopMenu.build() .setMenuList(new String[]{"選項1", "選項2", "選項3"}) .setDialogLifecycleCallback(new DialogLifecycleCallback() { @Override public void onShow(PopMenu dialog) { super.onShow(dialog); } @Override public void onDismiss(PopMenu dialog) { super.onDismiss(dialog); } }) .show(); ``` -------------------------------- ### Build GuideDialog with Builder Pattern Source: https://github.com/kongzue/dialogx/wiki/GuideDialog_tc Construct a GuideDialog using the builder pattern, allowing for method chaining to set various properties like the tip image. ```java GuideDialog.build() .setTipImage(R.mipmap.img_guide_tip) .show(); ``` -------------------------------- ### Handle Menu Item Clicks Source: https://github.com/kongzue/dialogx/wiki/PopMenu_tc Explains how to set a listener to handle clicks on menu items and retrieve selection information. ```APIDOC ## Handle Menu Item Clicks ### Description Sets a listener to be invoked when a menu item is clicked, allowing for custom actions and retrieval of selected item details. ### Method `.setOnMenuItemClickListener(OnMenuItemClickListener listener)` ### Parameters #### Path Parameters - **listener** (OnMenuItemClickListener) - Required - The listener to handle menu item clicks. ### Request Example ```java PopMenu.show("選項1", "選項2", "選項3") .setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onClick(PopMenu dialog, CharSequence text, int index) { // Handle click event return false; // Return true to consume the event } }); ``` ### Additional Notes - Use `dialog.getSelectIndex()` to get the index of the selected item. - Use `dialog.getSelectMenuText()` to get the text of the selected item. ``` -------------------------------- ### 对话框数据穿透:存储和获取数据 Source: https://github.com/kongzue/dialogx/wiki/高阶扩展用法 使用 `setData` 方法在对话框生命周期内临时存储任意对象,并使用 `getData` 方法获取存储的数据。这适用于对话框组件间共享数据、预存初始化参数或临时缓存用户操作记录。 ```java // 存储数据(支持任意对象类型) dialog.setData("userInfo", userObject) // 获取数据(自动类型适配) User user = dialog.getData("userInfo"); ```