# InterstitialDialogAction
The **InterstitialDialogAction** component is a dialog box used in atomic services to temporarily display information that requires user attention or actions to be taken while maintaining the current context. Users can trigger corresponding actions by clicking different areas of the dialog box.
> **NOTE**
>
> This component is supported since API version 12. Updates will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```
import { InterstitialDialogAction, IconStyle, TitlePosition, BottomOffset } from '@kit.ArkUI';
```
## Child Components
Not supported
## Attributes
The [universal attributes](ts-universal-attributes-size.md) are not supported.
## InterstitialDialogAction
Implements an **InterstitialDialogAction** instance. For details, see [Example](#example).
### constructor
constructor(dialogOptions: DialogOptions)
A constructor used to create an **InterstitialDialogAction** instance.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name| Type| Mandatory| Description|
| - | - | - | - |
| dialogOptions | [DialogOptions](#dialogoptions)| Yes| Attributes specific to the dialog box.|
### openDialog
openDialog(): void
Opens the dialog box.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
### closeDialog
closeDialog(): void
Closes the dialog box.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
## DialogOptions
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
Defines the attributes specific to the dialog box and custom click actions for the user.
| Name| Type| Mandatory| Description|
| - | - | - | - |
| uiContext | [UIContext](../js-apis-arkui-UIContext.md#uicontext) | Yes| UI context.|
| bottomOffsetType | [BottomOffset](#bottomoffset) | Yes| Bottom offset type of the dialog box.|
| title | [ResourceStr](ts-types.md#resourcestr) | No| Title of the dialog box.|
| subtitle | [ResourceStr](ts-types.md#resourcestr) | No| Subtitle of the dialog box.|
| titleColor | [ResourceStr](ts-types.md#resourcestr) \| [Color](ts-appendix-enums.md#color) | No| Font color of the dialog box title.|
| subtitleColor | [ResourceStr](ts-types.md#resourcestr) \| [Color](ts-appendix-enums.md#color) | No| Font color of the dialog box subtitle.|
| backgroundImage | [Resource](ts-types.md#resource) | No| Background image of the dialog box.|
| foregroundImage | [Resource](ts-types.md#resource) | No| Foreground image of the dialog box.|
| iconStyle | [IconStyle](#iconstyle) | No| Style of the close button icon (light or dark).
Default value: **[IconStyle](#iconstyle).Light**|
| titlePosition | [TitlePosition](#titleposition) | No| Vertical position of the title relative to the subtitle in the dialog box.
Default value: **[TitlePosition](#titleposition).Top**|
| onDialogClick | Callback\ | No| Custom action triggered by clicking anywhere on the dialog box.|
| onDialogClose | Callback\ | No| Custom action triggered by clicking the close button.|
## IconStyle
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
Sets the color style of the close button. By default, the close button is set to light color.
| Name| Value| Description|
| - | - | - |
| DARK | 0 | The close button is in dark color.|
| LIGHT | 1 | The close button is in light color.
Default value.|
## TitlePosition
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
Defines the vertical position of the title relative to the subtitle in the dialog box. By default, the title is above the subtitle.
| Name| Value| Description|
| - | - | - |
| TOP | 0 | The title is above the subtitle.
Default value.|
| BOTTOM | 1 | The title is below the subtitle.|
## BottomOffset
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
Defines the distance between the popup and the bottom in different scenario modes, based on the presence or absence of a menu bar, with the default being the distance when there is no menu bar.
| Name| Value| Description|
| - | - | - |
| OFFSET_FOR_BAR | 0 | Distance from the bottom of the window when there is a menu bar.
Default value. It sets the dialog box 88 vp away from the bottom of the window.|
| OFFSET_FOR_NONE | 1 | Distance from the bottom of the window when there is no menu bar.
It sets the dialog box 44 vp away from the bottom of the window.|
## Events
The [universal events](ts-universal-events-click.md) are not supported.
## Example
### Example 1
In this example,
color values are assigned to the title and subtitle using two different parameter types; the close button is set to dark color; the title is set to above the subtitle; and the distance type is set to the distance used when there is no menu bar.
```ts
// ../entryability/EntryAbility
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { window } from '@kit.ArkUI';
import { BusinessError } from '@kit.BasicServicesKit';
let dialogUIContext: UIContext | null = null;
export function getDialogUIContext(): UIContext | null {
return dialogUIContext;
}
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
}
onDestroy(): void {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage): void {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
});
let windowClass: window.Window | undefined = undefined;
windowStage.getMainWindow((err: BusinessError, data) => {
let errCode: number = err.code;
if (errCode) {
console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
return;
}
windowClass = data;
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
dialogUIContext = windowClass.getUIContext();
})
// Obtain the main window.
windowStage.getMainWindow((err, data) => {
if (err.code) {
console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
return;
}
windowClass = data;
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
// Set the window to full screen.
windowClass.setWindowLayoutFullScreen(false)
})
}
onWindowStageDestroy(): void {
// Main window is destroyed, release UI related resources
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground(): void {
// Ability has brought to foreground
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
}
onBackground(): void {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
}
}
```
```ts
// Index.ets
import { getDialogUIContext } from '../entryability/EntryAbility';
import { UIContext, InterstitialDialogAction, IconStyle, TitlePosition, BottomOffset } from '@kit.ArkUI';
@Entry
@Component
struct Index {
build() {
Row() {
Column() {
Text("show dialog")
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
let ctx: UIContext | null = getDialogUIContext();
let interstitialDialogAction: InterstitialDialogAction = new InterstitialDialogAction({
uiContext: ctx as UIContext,
title: "Title",
subtitle: "Subtitle",
titleColor: 'rgb(255, 192, 0)',
subtitleColor: Color.Red,
backgroundImage: $r('app.media.testBackgroundImg'),
foregroundImage: $r('app.media.testForegroundImg'),
iconStyle: IconStyle.DARK,
titlePosition: TitlePosition.TOP,
bottomOffsetType: BottomOffset.OFFSET_FOR_NONE,
onDialogClick: () => { console.log('outer dialog click action') },
onDialogClose: () => { console.log('outer close action') }
});
interstitialDialogAction.openDialog();
})
}
.width('100%')
}
.height('100%')
.backgroundColor('rgba(0, 0, 0, 0.1)')
}
}
```

### Example 2
In this example, color values are assigned to the title and subtitle using two different parameter types; the close button is set to light color; the title is set to below the subtitle; and the distance type is set to the distance used when there is a menu bar.
```ts
// ../entryability/EntryAbility
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { window } from '@kit.ArkUI';
import { BusinessError } from '@kit.BasicServicesKit';
let dialogUIContext: UIContext | null = null;
export function getDialogUIContext(): UIContext | null {
if (getDialogUIContext === null) {
hilog.info(0x0000, 'testTag', '%{public}s', 'getDialogUIContext is null');
}
return dialogUIContext;
}
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
}
onDestroy(): void {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage): void {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
});
let windowClass: window.Window | undefined = undefined;
windowStage.getMainWindow((err: BusinessError, data) => {
let errCode: number = err.code;
if (errCode) {
console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
return;
}
windowClass = data;
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
dialogUIContext = windowClass.getUIContext();
})
// Obtain the main window.
windowStage.getMainWindow((err, data) => {
if (err.code) {
console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
return;
}
windowClass = data;
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
// Set the window to full screen.
windowClass.setWindowLayoutFullScreen(false)
})
}
onWindowStageDestroy(): void {
// Main window is destroyed, release UI related resources
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground(): void {
// Ability has brought to foreground
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
}
onBackground(): void {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
}
}
```
```ts
// Index.ets
import { getDialogUIContext } from '../entryability/EntryAbility';
import { UIContext, InterstitialDialogAction, IconStyle, TitlePosition, BottomOffset } from '@kit.ArkUI';
@Entry
@Component
struct Index {
build() {
Row() {
Column() {
Text("show dialog")
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
let ctx: UIContext | null = getDialogUIContext();
let interstitialDialogAction: InterstitialDialogAction = new InterstitialDialogAction({
uiContext: ctx as UIContext,
title: "Title",
subtitle: "Subtitle",
titleColor: 'rgb(255, 192, 0)',
subtitleColor: Color.Red,
backgroundImage: $r('app.media.testBackgroundImg'),
foregroundImage: $r('app.media.testForegroundImg'),
iconStyle: IconStyle.LIGHT,
titlePosition: TitlePosition.BOTTOM,
bottomOffsetType: BottomOffset.OFFSET_FOR_BAR,
onDialogClick: () => { console.log('outer dialog click action') },
onDialogClose: () => { console.log('outer close action') }
});
interstitialDialogAction.openDialog();
})
}
.width('100%')
}
.height('100%')
.backgroundColor('rgba(0, 0, 0, 0.1)')
}
}
```
