IDialogListDialog, ToastDialogpublic class CommonDialog extends BaseDialog
You can customize dialogs by means of inheritance and encapsulation. When creating or inheriting dialogs in applications, you need to initialize the dialogs and manage their lifecycle.
BaseDialog| 限定符和类型 | 类 | 说明 |
|---|---|---|
static interface |
CommonDialog.DestroyedListener |
Interface that listens for dialog destruction events.
|
BaseDialog.DialogListener, BaseDialog.DisplayCallback, BaseDialog.RemoveCallbackIDialog.CheckBoxClickedListener, IDialog.ClickedListener, IDialog.ItemClickedListener, IDialog.KeyboardCallbackBUTTON_NUM, BUTTON1, BUTTON2, BUTTON3, DEF_RADIUS, ICON_NUM, ICON1, ICON2, ICON3| 构造器 | 说明 |
|---|---|
CommonDialog(Context context) |
A constructor used to create a
CommonDialog instance. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
boolean |
clickKeyDown(KeyEvent event) |
Called when a key on the keyboard is pressed.
|
boolean |
clickKeyUp(KeyEvent event) |
Called when a key on the keyboard is released.
|
protected void |
create() |
Creates a
Dialog instance. |
void |
dealBackKeyDown() |
Called when the Back key is pressed and released.
|
boolean |
dealTouchEvent(TouchEvent event) |
Called when a touch was pressed event.
|
boolean |
deliverKeyboardCase(KeyEvent event) |
Delivers a specified keyboard event.
|
boolean |
deliverTouchCase(TouchEvent event) |
Delivers a specified touch event.
|
Rect |
getBoundRect() |
Obtains the bounds of a moving window.
|
Component |
getButtonComponent() |
Obtains the content of button area.
|
Component |
getContentCustomComponent() |
Obtains the content displayed in the content area.
|
Window |
getWindow() |
Obtains the window corresponding to a dialog box.
|
boolean |
isMovable() |
Checks whether a window is movable.
|
protected void |
onCreate() |
Called from
BaseDialog to set the default layout for the current dialog box. |
protected void |
onDestroy() |
Callback interface used when enabling automatic close of a
Dialog instance. |
protected void |
onShow() |
Called from
BaseDialog to initialize the content of the panels. |
protected void |
onWindowConfigUpdated(WindowManager.LayoutConfig configParam) |
Called when the window layout parameters change.
|
protected void |
onWindowSelectionUpdated(boolean isSelectionUpdated) |
Called when the window selection state changes.
|
void |
setBoundRect(Rect boundRect) |
Sets the bounds of a moving window.
|
CommonDialog |
setButton(int buttonNum,
String text,
IDialog.ClickedListener listener) |
Sets the buttons in the button area.
|
CommonDialog |
setContentCustomComponent(Component component) |
Customizes the content area.
|
CommonDialog |
setContentImage(int resId) |
Sets the icon to be displayed in the content area.
|
CommonDialog |
setContentText(String text) |
Sets the text to be displayed in the content area.
|
void |
setDestroyedListener(CommonDialog.DestroyedListener destroyedListener) |
Sets the dialog destruction listener.
|
CommonDialog |
setImageButton(int buttonNum,
int resId,
IDialog.ClickedListener listener) |
Sets the image button for a
CommonDialog object. |
void |
setMovable(boolean movable) |
Sets whether a window is movable.
|
boolean |
setSwipeToDismiss(boolean isEnabled) |
Sets whether to enable the feature of exiting a dialog by swiping right on the screen.Use this method after
BaseDialog.show() is called. |
CommonDialog |
setTitleCustomComponent(DirectionalLayout component) |
Customizes the title area.
|
CommonDialog |
setTitleIcon(int resId,
int iconId) |
Sets the icon in the title area.
|
CommonDialog |
setTitleSubText(String text) |
Sets the supplementary text information in the title area.
|
CommonDialog |
setTitleText(String text) |
Sets the title text in the title area.
|
void |
siteKeyboardCallback(IDialog.KeyboardCallback keyboardCallback) |
Sets a callback for keyboard events.
|
void |
siteRemovable(boolean removable) |
Sets whether to remove the dialog box when the user taps the Back key.
|
destroy, hide, isShowing, obtainComponentViaId, onHide, onShowing, registerDisplayCallback, registerRemoveCallback, remove, searchComponentViaId, setAlignment, setAutoClosable, setCornerRadius, setDialogListener, setDuration, setOffset, setSize, setTransparent, showpublic CommonDialog(Context context)
CommonDialog instance.
The caller needs to pass in a valid context in order to construct a dialog.
context - Indicates the ohos context.protected void create()
BaseDialogDialog instance.
This method takes priority over the BaseDialog.onShow() method.
create 在类中 BaseDialogprotected void onWindowConfigUpdated(WindowManager.LayoutConfig configParam)
configParam - Indicates the window layout parameters.protected void onWindowSelectionUpdated(boolean isSelectionUpdated)
isSelectionUpdated - Specifies whether the window is selected.
The value true indicates that the window is selected,
and false indicates the opposite.public boolean isMovable()
true if the window is movable; returns false otherwise.public void setMovable(boolean movable)
movable - Indicates whether the window is movable.
true indicates the window is movable;
false indicates the window is not movable.public Rect getBoundRect()
public void setBoundRect(Rect boundRect)
boundRect - Indicates the bounds of the window, in shape of rectangle.public CommonDialog setTitleIcon(int resId, int iconId)
Three locations have been reserved for icons in the title area. You can specify where you want the icon to locate by specifying the location ID.
resId - Indicates the resource id of the icon to be displayed in the title area.iconId - Indicates the location in the title area where you want the icon to be.
There are three options: (0) in front of the text; (1) in the middle; and (2) after the text.CommonDialog object for continuous operations,
for example, obj.setTitleText(text).show().IDialogpublic CommonDialog setTitleText(String text)
The title area has reserved space for both the title and subtitle. The subtitle can be set only after the title has been set.
text - Indicates the text content of the title to display.CommonDialog object for continuous operations,
for example, obj.setTitleText(text).show().public CommonDialog setTitleSubText(String text)
The supplementary information complements the title to make the information clearer. It can be left blank.
text - Indicates the supplementary text information to display.CommonDialog object for continuous operations,
for example, obj.setTitleText(text).show().public CommonDialog setTitleCustomComponent(DirectionalLayout component)
component - Indicates the customized DirectionalLayout object that encapsulates the component
to be displayed.CommonDialog object for continuous operations,
for example, obj.setTitleText(text).show().public CommonDialog setContentImage(int resId)
The content area cannot be empty. It must contain either an icon or text, or both; or use a customized content area.
resId - Indicates the resource id of the content to be displayed.CommonDialog object for continuous operations,
for example, obj.setTitleText(text).show().public CommonDialog setContentText(String text)
The content area cannot be empty. It must contain either an icon or text, or both; or use a customized content area.
text - Indicates the text information to display in the content area.CommonDialog object for continuous operations,
for example, obj.setTitleText(text).show().public CommonDialog setContentCustomComponent(Component component)
The content area cannot be empty. It must contain at least an icon or a text, or use a customized content area.
component - Indicates the customized component.CommonDialog object for continuous operations,
for example, obj.setTitleText(text).show().public Component getContentCustomComponent()
This method obtains the outermost ComponentContainer, which contains all the displayed content.
Component object.public Component getButtonComponent()
This method obtains the outermost ComponentContainer, which contains all the displayed button.
Component object.public Window getWindow()
public CommonDialog setButton(int buttonNum, String text, IDialog.ClickedListener listener)
The button area can have a maximum of three buttons by default.
buttonNum - Indicates the button location. There are three options:
(0) the first button; (1) the button in the middle; and (2) the last button.text - Indicates the text displayed on the button.listener - Indicates the listener for detecting button pressing and releasing events.CommonDialog object for continuous operations,
for example, obj.setTitleText(text).show().IDialogpublic CommonDialog setImageButton(int buttonNum, int resId, IDialog.ClickedListener listener)
CommonDialog object.buttonNum - Indicates the position of the image button.
The numbers 0, 1, and 2 specify that the image button is located at the start,
in the middle, and at the end respectively.resId - Indicates the resource id of the image button resource.listener - Indicates the listener for image button pressing and releasing events.CommonDialog object for continuous operations,
for example, obj.setTitleText(text).show().IDialogprotected void onCreate()
BaseDialog to set the default layout for the current dialog box.onCreate 在类中 BaseDialogprotected void onShow()
BaseDialog to initialize the content of the panels.onShow 在类中 BaseDialogprotected void onDestroy()
BaseDialogDialog instance.
This callback is triggered only when the BaseDialog.destroy() method is invoked.
onDestroy 在类中 BaseDialogpublic void setDestroyedListener(CommonDialog.DestroyedListener destroyedListener)
This listener is responsible for necessary handling before dialog destruction.
destroyedListener - Indicates the dialog destruction listener.public boolean setSwipeToDismiss(boolean isEnabled)
BaseDialog.show() is called.isEnabled - Specifies whether to enable the feature of exiting the dialog by swiping on the screen.
{code true} indicates enabled; false indicates disabled.true if this feature is enabled; returns false otherwise.public boolean deliverKeyboardCase(KeyEvent event)
event - Indicates the keyboard event to deliver.true if the keyboard event is successfully delivered;
returns false if the keyboard event fails to be delivered and if both
clickKeyDown(ohos.multimodalinput.event.KeyEvent) and clickKeyUp(ohos.multimodalinput.event.KeyEvent)
have returned false.public boolean clickKeyDown(KeyEvent event)
event - Indicates the key press event.true if the key press event is handled;
returns false (default) otherwise.public boolean clickKeyUp(KeyEvent event)
event - Indicates the key release event.true if the key release event is handled;
returns false (default) otherwise.public boolean deliverTouchCase(TouchEvent event)
event - Indicates the touch event to deliver.true if the touch event is successfully delivered or
has been handled via dealTouchEvent(ohos.multimodalinput.event.TouchEvent); returns false otherwise.public boolean dealTouchEvent(TouchEvent event)
event - Indicates the touch event to deal.false for default.public void siteKeyboardCallback(IDialog.KeyboardCallback keyboardCallback)
keyboardCallback - Indicates the callback to set.
The callback can handle keyboard events before the dialog box does.
Keyboard events that have been handled by the callback will be ignored by the dialog box.public void siteRemovable(boolean removable)
removable - Specifies whether to remove the dialog box.
The value true means to remove the dialog box,
and false means the opposite.public void dealBackKeyDown()