• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.promptAction (弹窗)
2
3创建并显示文本提示框、对话框和操作菜单。
4
5> **说明:**
6>
7> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>
9> 该模块不支持在[UIAbility](../apis-ability-kit/js-apis-app-ability-uiAbility.md)的文件声明处使用,即不能在UIAbility的生命周期中调用,需要在创建组件实例后使用。
10>
11> 本模块功能依赖UI的执行上下文,不可在UI上下文不明确的地方使用,参见[UIContext](js-apis-arkui-UIContext.md#uicontext)说明。建议在<!--Del-->除[ServiceExtension](../../application-models/serviceextensionability.md)等<!--DelEnd-->无UI界面的场景外,均使用UIContext中的弹窗方法。
12
13## 导入模块
14
15```ts
16import { promptAction } from '@kit.ArkUI';
17```
18
19## promptAction.openToast<sup>18+</sup>
20
21openToast(options: ShowToastOptions): Promise&lt;number&gt;
22
23显示文本提示框并返回文本提示框id。
24
25**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
26
27**系统能力:** SystemCapability.ArkUI.ArkUI.Full
28
29**参数**
30
31| 参数名  | 类型                                                         | 必填 | 说明           |
32| ------- | ------------------------------------------------------------ | ---- | -------------- |
33| options | [ShowToastOptions](#showtoastoptions) | 是   | 文本弹窗选项。 |
34
35**返回值**
36
37| 类型             | 说明                                 |
38| ---------------- | ------------------------------------ |
39| Promise&lt;number&gt; | 返回供closeToast使用的文本提示框id。 |
40
41**错误码:**
42
43以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.promptAction(弹窗)](errorcode-promptAction.md)错误码。
44
45| 错误码ID | 错误信息                                                     |
46| -------- | ------------------------------------------------------------ |
47| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. |
48| 100001   | Internal error.                                              |
49
50**示例:**
51
52```ts
53import { promptAction } from '@kit.ArkUI';
54import { BusinessError } from '@kit.BasicServicesKit';
55
56@Entry
57@Component
58struct toastExample {
59  @State toastId: number = 0;
60
61  build() {
62    Column() {
63      Button('Open Toast')
64        .height(100)
65        .type(ButtonType.Capsule)
66        .onClick(() => {
67          promptAction.openToast({
68            message: 'Toast Massage',
69            duration: 10000,
70          }).then((toastId: number) => {
71            this.toastId = toastId;
72          })
73            .catch((error: BusinessError) => {
74              console.error(`openToast error code is ${error.code}, message is ${error.message}`)
75            })
76        })
77      Blank().height(50);
78      Button('Close Toast')
79        .height(100)
80        .type(ButtonType.Capsule)
81        .onClick(() => {
82          try {
83            promptAction.closeToast(this.toastId);
84          } catch (error) {
85            let message = (error as BusinessError).message;
86            let code = (error as BusinessError).code;
87            console.error(`CloseToast error code is ${code}, message is ${message}`);
88          };
89        })
90    }.height('100%').width('100%').justifyContent(FlexAlign.Center)
91  }
92}
93```
94
95![toast-openclose](figures/toast-openclose.gif)
96
97## promptAction.closeToast<sup>18+</sup>
98
99closeToast(toastId: number): void
100
101关闭文本提示框。
102
103**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
104
105**系统能力:** SystemCapability.ArkUI.ArkUI.Full
106
107**参数**
108
109| 参数名  | 类型   | 必填 | 说明                          |
110| ------- | ------ | ---- | ----------------------------- |
111| toastId | number | 是   | openToast返回的文本提示框id。 |
112
113**错误码:**
114
115以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.promptAction(弹窗)](errorcode-promptAction.md)错误码。
116
117| 错误码ID | 错误信息                                                     |
118| -------- | ------------------------------------------------------------ |
119| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. |
120| 100001   | Internal error.                                              |
121
122**示例:**
123
124示例请看[promptAction.openToaset18](#promptactionopentoast18)的示例。
125
126## promptAction.showToast<sup>(deprecated)</sup>
127
128showToast(options: ShowToastOptions): void
129
130创建并显示文本提示框。
131
132> **说明:**
133>
134> 从API version 18开始废弃,建议使用[UIContext](js-apis-arkui-UIContext.md#uicontext)中的[getPromptAction](js-apis-arkui-UIContext.md#getpromptaction)获取[PromptAction](js-apis-arkui-UIContext.md#promptaction)实例,再通过此实例调用替代方法[showToast](js-apis-arkui-UIContext.md#showtoast)。
135>
136> 从API version 10开始,可以通过使用[UIContext](js-apis-arkui-UIContext.md#uicontext)中的[getPromptAction](js-apis-arkui-UIContext.md#getpromptaction)方法获取当前UI上下文关联的[PromptAction](js-apis-arkui-UIContext.md#promptaction)对象。
137
138**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
139
140**系统能力:** SystemCapability.ArkUI.ArkUI.Full
141
142**参数:**
143
144| 参数名     | 类型                                    | 必填   | 说明      |
145| ------- | ------------------------------------- | ---- | ------- |
146| options | [ShowToastOptions](#showtoastoptions) | 是    | 文本弹窗选项。 |
147
148**错误码:**
149
150以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.promptAction(弹窗)](errorcode-promptAction.md)错误码。
151
152| 错误码ID   | 错误信息 |
153| --------- | ------- |
154| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
155| 100001    | Internal error. |
156
157**示例:**
158
159```ts
160import { promptAction } from '@kit.ArkUI'
161import { BusinessError } from '@kit.BasicServicesKit';
162
163@Entry
164@Component
165struct toastExample {
166  build() {
167    Column() {
168      Button('Show toast').fontSize(20)
169        .onClick(() => {
170          try {
171            promptAction.showToast({
172              message: 'Hello World',
173              duration: 2000
174            });
175          } catch (error) {
176            let message = (error as BusinessError).message
177            let code = (error as BusinessError).code
178            console.error(`showToast args error code is ${code}, message is ${message}`);
179          };
180        })
181    }.height('100%').width('100%').justifyContent(FlexAlign.Center)
182  }
183}
184```
185API version 11及之前Toast样式。
186
187![zh-cn_image_0001](figures/toast-api11.gif)
188
189API version 12及之后Toast样式。
190
191![zh-cn_image_0001](figures/toast-api12.gif)
192
193## promptAction.showDialog<sup>(deprecated)</sup>
194
195showDialog(options: ShowDialogOptions): Promise&lt;ShowDialogSuccessResponse&gt;
196
197创建并显示对话框,对话框响应后异步返回结果。
198
199> **说明:**
200>
201> 从API version 18开始废弃,建议使用[UIContext](js-apis-arkui-UIContext.md#uicontext)中的[getPromptAction](js-apis-arkui-UIContext.md#getpromptaction)获取[PromptAction](js-apis-arkui-UIContext.md#promptaction)实例,再通过此实例调用替代方法[showDialog](js-apis-arkui-UIContext.md#showdialog-1)。
202>
203> 从API version 10开始,可以通过使用[UIContext](js-apis-arkui-UIContext.md#uicontext)中的[getPromptAction](js-apis-arkui-UIContext.md#getpromptaction)方法获取当前UI上下文关联的[PromptAction](js-apis-arkui-UIContext.md#promptaction)对象。
204
205**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
206
207**系统能力:**  SystemCapability.ArkUI.ArkUI.Full
208
209**参数:**
210
211| 参数名     | 类型                                      | 必填   | 说明     |
212| ------- | --------------------------------------- | ---- | ------ |
213| options | [ShowDialogOptions](#showdialogoptions) | 是    | 对话框选项。 |
214
215**返回值:**
216
217| 类型                                       | 说明       |
218| ---------------------------------------- | -------- |
219| Promise&lt;[ShowDialogSuccessResponse](#showdialogsuccessresponse)&gt; | 对话框响应结果。 |
220
221**错误码:**
222
223以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.promptAction(弹窗)](errorcode-promptAction.md)错误码。
224
225| 错误码ID   | 错误信息 |
226| --------- | ------- |
227| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
228| 100001    | Internal error. |
229
230**示例:**
231
232```ts
233import { promptAction } from '@kit.ArkUI'
234
235promptAction.showDialog({
236  title: 'Title Info',
237  message: 'Message Info',
238  buttons: [
239    {
240      text: 'button1',
241      color: '#000000'
242    },
243    {
244      text: 'button2',
245      color: '#000000'
246    }
247  ],
248})
249  .then(data => {
250    console.info('showDialog success, click button: ' + data.index);
251  })
252  .catch((err: Error) => {
253    console.info('showDialog error: ' + err);
254  })
255```
256
257![zh-cn_image_0002](figures/zh-cn_image_0002.gif)
258
259## promptAction.showDialog<sup>(deprecated)</sup>
260
261showDialog(options: ShowDialogOptions, callback: AsyncCallback&lt;ShowDialogSuccessResponse&gt;):void
262
263创建并显示对话框,对话框响应结果异步返回。
264
265> **说明:**
266>
267> 从API version 18开始废弃,建议使用[UIContext](js-apis-arkui-UIContext.md#uicontext)中的[getPromptAction](js-apis-arkui-UIContext.md#getpromptaction)获取[PromptAction](js-apis-arkui-UIContext.md#promptaction)实例,再通过此实例调用替代方法[showDialog](js-apis-arkui-UIContext.md#showdialog)。
268>
269> 从API version 10开始,可以通过使用[UIContext](js-apis-arkui-UIContext.md#uicontext)中的[getPromptAction](js-apis-arkui-UIContext.md#getpromptaction)方法获取当前UI上下文关联的[PromptAction](js-apis-arkui-UIContext.md#promptaction)对象。
270
271**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
272
273**系统能力:**  SystemCapability.ArkUI.ArkUI.Full
274
275**参数:**
276
277| 参数名      | 类型                                       | 必填   | 说明           |
278| -------- | ---------------------------------------- | ---- | ------------ |
279| options  | [ShowDialogOptions](#showdialogoptions)  | 是    | 页面显示对话框信息描述。 |
280| callback | AsyncCallback&lt;[ShowDialogSuccessResponse](#showdialogsuccessresponse)&gt; | 是    | 对话框响应结果回调。   |
281
282**错误码:**
283
284以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.promptAction(弹窗)](errorcode-promptAction.md)错误码。
285
286| 错误码ID   | 错误信息 |
287| --------- | ------- |
288| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
289| 100001    | Internal error. |
290
291**示例:**
292
293```ts
294import { promptAction } from '@kit.ArkUI';
295import { BusinessError } from '@kit.BasicServicesKit';
296
297try {
298  promptAction.showDialog({
299    title: 'showDialog Title Info',
300    message: 'Message Info',
301    buttons: [
302      {
303        text: 'button1',
304        color: '#000000'
305      },
306      {
307        text: 'button2',
308        color: '#000000'
309      }
310    ]
311  }, (err, data) => {
312    if (err) {
313      console.info('showDialog err: ' + err);
314      return;
315    }
316    console.info('showDialog success callback, click button: ' + data.index);
317  });
318} catch (error) {
319  let message = (error as BusinessError).message
320  let code = (error as BusinessError).code
321  console.error(`showDialog args error code is ${code}, message is ${message}`);
322};
323```
324
325![zh-cn_image_0004](figures/zh-cn_image_0004.gif)
326
327当弹窗的showInSubWindow属性为true时,弹窗可显示在窗口外。
328
329```ts
330import { promptAction } from '@kit.ArkUI';
331import { BusinessError } from '@kit.BasicServicesKit';
332
333try {
334  promptAction.showDialog({
335    title: 'showDialog Title Info',
336    message: 'Message Info',
337    isModal: true,
338    showInSubWindow: true,
339    buttons: [
340      {
341        text: 'button1',
342        color: '#000000'
343      },
344      {
345        text: 'button2',
346        color: '#000000'
347      }
348    ]
349  }, (err, data) => {
350    if (err) {
351      console.info('showDialog err: ' + err);
352      return;
353    }
354    console.info('showDialog success callback, click button: ' + data.index);
355  });
356} catch (error) {
357  let message = (error as BusinessError).message
358  let code = (error as BusinessError).code
359  console.error(`showDialog args error code is ${code}, message is ${message}`);
360};
361```
362
363![zh-cn_image_0002_showinsubwindow](figures/zh-cn_image_0002_showinsubwindow.jpg)
364
365
366
367## promptAction.showActionMenu<sup>(deprecated)</sup>
368
369showActionMenu(options: ActionMenuOptions, callback: AsyncCallback&lt;ActionMenuSuccessResponse&gt;):void
370
371创建并显示操作菜单,菜单响应结果异步返回。
372
373> **说明:**
374>
375> 从API version 18开始废弃,建议使用[UIContext](js-apis-arkui-UIContext.md#uicontext)中的[getPromptAction](js-apis-arkui-UIContext.md#getpromptaction)获取[PromptAction](js-apis-arkui-UIContext.md#promptaction)实例,再通过此实例调用替代方法[showActionMenu](js-apis-arkui-UIContext.md#showactionmenu11)。
376>
377> 从API version 11开始,可以通过使用[UIContext](js-apis-arkui-UIContext.md#uicontext)中的[getPromptAction](js-apis-arkui-UIContext.md#getpromptaction)方法获取当前UI上下文关联的[PromptAction](js-apis-arkui-UIContext.md#promptaction)对象。
378
379**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
380
381**系统能力:** SystemCapability.ArkUI.ArkUI.Full382
383**参数:**
384
385| 参数名      | 类型                                       | 必填   | 说明        |
386| -------- | ---------------------------------------- | ---- | --------- |
387| options  | [ActionMenuOptions](#actionmenuoptions)  | 是    | 操作菜单选项。   |
388| callback | AsyncCallback&lt;[ActionMenuSuccessResponse](#actionmenusuccessresponse)> | 是    | 菜单响应结果回调。 |
389
390**错误码:**
391
392以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.promptAction(弹窗)](errorcode-promptAction.md)错误码。
393
394| 错误码ID   | 错误信息 |
395| --------- | ------- |
396| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
397| 100001    | Internal error. |
398
399**示例:**
400
401```ts
402import { promptAction } from '@kit.ArkUI';
403import { BusinessError } from '@kit.BasicServicesKit';
404
405try {
406  promptAction.showActionMenu({
407    title: 'Title Info',
408    buttons: [
409      {
410        text: 'item1',
411        color: '#666666'
412      },
413      {
414        text: 'item2',
415        color: '#000000'
416      },
417    ]
418  }, (err, data) => {
419    if (err) {
420      console.info('showActionMenu err: ' + err);
421      return;
422    }
423    console.info('showActionMenu success callback, click button: ' + data.index);
424  })
425} catch (error) {
426  let message = (error as BusinessError).message
427  let code = (error as BusinessError).code
428  console.error(`showActionMenu args error code is ${code}, message is ${message}`);
429};
430```
431
432![zh-cn_image_0005](figures/zh-cn_image_0005.gif)
433
434## promptAction.showActionMenu<sup>(deprecated)</sup>
435
436showActionMenu(options: ActionMenuOptions): Promise&lt;ActionMenuSuccessResponse&gt;
437
438创建并显示操作菜单,菜单响应后异步返回结果。
439
440> **说明:**
441>
442> 从API version 18开始废弃,建议使用[UIContext](js-apis-arkui-UIContext.md#uicontext)中的[getPromptAction](js-apis-arkui-UIContext.md#getpromptaction)获取[PromptAction](js-apis-arkui-UIContext.md#promptaction)实例,再通过此实例调用替代方法[showActionMenu](js-apis-arkui-UIContext.md#showactionmenu)。
443>
444> 从API version 10开始,可以通过使用[UIContext](js-apis-arkui-UIContext.md#uicontext)中的[getPromptAction](js-apis-arkui-UIContext.md#getpromptaction)方法获取当前UI上下文关联的[PromptAction](js-apis-arkui-UIContext.md#promptaction)对象。
445
446**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
447
448**系统能力:** SystemCapability.ArkUI.ArkUI.Full
449
450**参数:**
451
452| 参数名     | 类型                                      | 必填   | 说明      |
453| ------- | --------------------------------------- | ---- | ------- |
454| options | [ActionMenuOptions](#actionmenuoptions) | 是    | 操作菜单选项。 |
455
456**返回值:**
457
458| 类型                                       | 说明      |
459| ---------------------------------------- | ------- |
460| Promise&lt;[ActionMenuSuccessResponse](#actionmenusuccessresponse)&gt; | 菜单响应结果。 |
461
462**错误码:**
463
464以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.promptAction(弹窗)](errorcode-promptAction.md)错误码。
465
466| 错误码ID   | 错误信息 |
467| --------- | ------- |
468| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
469| 100001    | Internal error. |
470
471**示例:**
472
473```ts
474import { promptAction } from '@kit.ArkUI';
475
476promptAction.showActionMenu({
477  title: 'showActionMenu Title Info',
478  buttons: [
479    {
480      text: 'item1',
481      color: '#666666'
482    },
483    {
484      text: 'item2',
485      color: '#000000'
486    },
487  ]
488})
489  .then(data => {
490    console.info('showActionMenu success, click button: ' + data.index);
491  })
492  .catch((err: Error) => {
493    console.info('showActionMenu error: ' + err);
494  })
495```
496
497![zh-cn_image_0006](figures/zh-cn_image_0006.gif)
498
499## promptAction.openCustomDialog<sup>(deprecated)</sup>
500
501openCustomDialog(options: CustomDialogOptions): Promise&lt;number&gt;
502
503打开自定义弹窗。
504
505<!--Del-->不支持在ServiceExtension中使用。<!--DelEnd-->
506
507暂不支持isModal = true与showInSubWindow = true同时使用。
508
509弹窗宽度在设备竖屏时默认为 所在窗口宽度 - 左右margin(16vp,设备为2in1时为40vp),最大默认宽度为400vp。
510
511> **说明:**
512>
513> 从API version 11开始支持,从API version 18开始废弃,建议使用[UIContext](js-apis-arkui-UIContext.md#uicontext)中的[getPromptAction](js-apis-arkui-UIContext.md#getpromptaction)获取[PromptAction](js-apis-arkui-UIContext.md#promptaction)实例,再通过此实例调用替代方法[openCustomDialog](js-apis-arkui-UIContext.md#opencustomdialog12-1)。
514>
515> 从API version 12开始,可以通过使用[UIContext](js-apis-arkui-UIContext.md#uicontext)中的[getPromptAction](js-apis-arkui-UIContext.md#getpromptaction)方法获取当前UI上下文关联的[PromptAction](js-apis-arkui-UIContext.md#promptaction)对象。
516
517**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
518
519**系统能力:** SystemCapability.ArkUI.ArkUI.Full
520
521**参数:**
522
523| 参数名  | 类型                                          | 必填 | 说明               |
524| ------- | --------------------------------------------- | ---- | ------------------ |
525| options | [CustomDialogOptions](#customdialogoptions11) | 是   | 自定义弹窗的内容。 |
526
527**返回值:**
528
529| 类型                  | 说明                                  |
530| --------------------- | ------------------------------------- |
531| Promise&lt;number&gt; | 返回供closeCustomDialog使用的对话框id。 |
532
533**错误码:**
534
535以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.promptAction(弹窗)](errorcode-promptAction.md)错误码。
536
537| 错误码ID | 错误信息                           |
538| -------- | ---------------------------------- |
539| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
540| 100001   | Internal error. |
541
542**示例:**
543
544```ts
545import { promptAction } from '@kit.ArkUI'
546import { BusinessError } from '@kit.BasicServicesKit'
547
548@Entry
549@Component
550struct Index {
551  private customDialogComponentId: number = 0
552
553  @Builder
554  customDialogComponent() {
555    Column() {
556      Text('弹窗').fontSize(30)
557      Row({ space: 50 }) {
558        Button("确认").onClick(() => {
559          try {
560            promptAction.closeCustomDialog(this.customDialogComponentId)
561          } catch (error) {
562            let message = (error as BusinessError).message;
563            let code = (error as BusinessError).code;
564            console.error(`closeCustomDialog error code is ${code}, message is ${message}`);
565          }
566        })
567        Button("取消").onClick(() => {
568          try {
569            promptAction.closeCustomDialog(this.customDialogComponentId)
570          } catch (error) {
571            let message = (error as BusinessError).message;
572            let code = (error as BusinessError).code;
573            console.error(`closeCustomDialog error code is ${code}, message is ${message}`);
574          }
575        })
576      }
577    }.height(200).padding(5).justifyContent(FlexAlign.SpaceBetween)
578  }
579
580  build() {
581    Row() {
582      Column({ space: 20 }) {
583        Text('组件内弹窗')
584          .fontSize(30)
585          .onClick(() => {
586            promptAction.openCustomDialog({
587              builder: () => {
588                this.customDialogComponent()
589              },
590              onWillDismiss: (dismissDialogAction: DismissDialogAction) => {
591                console.info("reason" + JSON.stringify(dismissDialogAction.reason))
592                console.log("dialog onWillDismiss")
593                if (dismissDialogAction.reason == DismissReason.PRESS_BACK) {
594                  dismissDialogAction.dismiss()
595                }
596                if (dismissDialogAction.reason == DismissReason.TOUCH_OUTSIDE) {
597                  dismissDialogAction.dismiss()
598                }
599              }
600            }).then((dialogId: number) => {
601              this.customDialogComponentId = dialogId
602            })
603              .catch((error: BusinessError) => {
604                console.error(`openCustomDialog error code is ${error.code}, message is ${error.message}`)
605              })
606          })
607      }
608      .width('100%')
609    }
610    .height('100%')
611  }
612}
613
614```
615该示例定义了弹窗样式,如宽度、高度、背景色、阴影等等。
616
617> **说明:**
618>
619> 直接使用openCustomDialog可能导致实例不明确的问题,建议使用[UIContext](js-apis-arkui-UIContext.md#uicontext)中的[getPromptAction](js-apis-arkui-UIContext.md#getpromptaction)获取[PromptAction](js-apis-arkui-UIContext.md#promptaction)实例,再通过此实例调用替代方法[openCustomDialog](js-apis-arkui-UIContext.md#opencustomdialog12-1)。
620
621```ts
622import { LevelMode, ImmersiveMode } from '@kit.ArkUI'
623
624let customDialogId: number = 0;
625
626@Builder
627function customDialogBuilder(uiContext: UIContext) {
628  Column() {
629    Text('Custom dialog Message').fontSize(10)
630    Row() {
631      Button("确认").onClick(() => {
632        uiContext.getPromptAction().closeCustomDialog(customDialogId)
633      })
634      Blank().width(50)
635      Button("取消").onClick(() => {
636        uiContext.getPromptAction().closeCustomDialog(customDialogId)
637      })
638    }
639  }
640}
641
642@Entry
643@Component
644struct Index {
645  @State message: string = 'Hello World';
646  private uiContext: UIContext = this.getUIContext();
647
648  @Builder
649  customDialogComponent() {
650    customDialogBuilder(this.uiContext)
651  }
652
653  build() {
654    Row() {
655      Column() {
656        Text(this.message).id("test_text")
657          .fontSize(50)
658          .fontWeight(FontWeight.Bold)
659          .onClick(() => {
660            const node: FrameNode | null = this.uiContext.getFrameNodeById("test_text") || null;
661            this.uiContext.getPromptAction().openCustomDialog({
662              builder: () => {
663                this.customDialogComponent()
664              },
665              keyboardAvoidMode: KeyboardAvoidMode.NONE,
666              showInSubWindow: false,
667              offset: { dx: 5, dy: 5 },
668              backgroundColor: 0xd9ffffff,
669              cornerRadius: 20,
670              width: '80%',
671              height: 200,
672              borderWidth: 1,
673              borderStyle: BorderStyle.Dashed, // 使用borderStyle属性,需要和borderWidth属性一起使用
674              borderColor: Color.Blue, // 使用borderColor属性,需要和borderWidth属性一起使用
675              shadow: ({
676                radius: 20,
677                color: Color.Grey,
678                offsetX: 50,
679                offsetY: 0
680              }),
681              levelMode: LevelMode.EMBEDDED,
682              levelUniqueId: node?.getUniqueId(),
683              immersiveMode: ImmersiveMode.DEFAULT,
684            }).then((dialogId: number) => {
685              customDialogId = dialogId;
686            })
687          })
688      }
689      .width('100%')
690    }
691    .height('100%')
692  }
693}
694```
695![zh-cn_image_0007](figures/zh-cn_image_0007.gif)
696
697该示例实现了一个页面内的弹窗。
698
699> **说明:**
700>
701> 直接使用openCustomDialog可能导致实例不明确的问题,建议使用[UIContext](js-apis-arkui-UIContext.md#uicontext)中的[getPromptAction](js-apis-arkui-UIContext.md#getpromptaction)获取[PromptAction](js-apis-arkui-UIContext.md#promptaction)实例,再通过此实例调用替代方法[openCustomDialog](js-apis-arkui-UIContext.md#opencustomdialog12-1)。
702
703```ts
704// Index.ets
705import { LevelMode, ImmersiveMode } from '@kit.ArkUI'
706
707let customDialogId: number = 0;
708
709@Builder
710function customDialogBuilder(uiContext: UIContext) {
711  Column() {
712    Text('Custom dialog Message').fontSize(10).height(100)
713    Row() {
714      Button("Next").onClick(() => {
715        uiContext.getRouter().pushUrl({ url: 'pages/Next' })
716      })
717      Blank().width(50)
718      Button("Close").onClick(() => {
719        uiContext.getPromptAction().closeCustomDialog(customDialogId)
720      })
721    }
722  }.padding(20)
723}
724
725@Entry
726@Component
727struct Index {
728  @State message: string = 'Hello World';
729  private uiContext: UIContext = this.getUIContext();
730
731  @Builder
732  customDialogComponent() {
733    customDialogBuilder(this.uiContext)
734  }
735
736  build() {
737    Row() {
738      Column() {
739        Text(this.message).id("test_text")
740          .fontSize(50)
741          .fontWeight(FontWeight.Bold)
742          .onClick(() => {
743            const node: FrameNode | null = this.uiContext.getFrameNodeById("test_text") || null;
744            this.uiContext.getPromptAction().openCustomDialog({
745              builder: () => {
746                this.customDialogComponent()
747              },
748              levelMode: LevelMode.EMBEDDED,
749              levelUniqueId: node?.getUniqueId(),
750              immersiveMode: ImmersiveMode.DEFAULT,
751            }).then((dialogId: number) => {
752              customDialogId = dialogId;
753            })
754          })
755      }
756      .width('100%')
757    }
758    .height('100%')
759  }
760}
761```
762```ts
763// Next.ets
764@Entry
765@Component
766struct Next {
767  @State message: string = 'Back';
768
769  build() {
770    Row() {
771      Column() {
772        Button(this.message)
773          .onClick(() => {
774            this.getUIContext().getRouter().back()
775          })
776      }
777      .width('100%')
778    }
779    .height('100%')
780  }
781}
782```
783![embedded_dialog](figures/embedded_dialog.gif)
784
785## promptAction.closeCustomDialog<sup>(deprecated)</sup>
786
787closeCustomDialog(dialogId: number): void
788
789关闭自定义弹窗。
790
791> **说明:**
792>
793> 从API version 11开始支持,从API version 18开始废弃,建议使用[UIContext](js-apis-arkui-UIContext.md#uicontext)中的[getPromptAction](js-apis-arkui-UIContext.md#getpromptaction)获取[PromptAction](js-apis-arkui-UIContext.md#promptaction)实例,再通过此实例调用替代方法[closeCustomDialog](js-apis-arkui-UIContext.md#closecustomdialog12-1)。
794>
795> 从API version 12开始,可以通过使用[UIContext](js-apis-arkui-UIContext.md#uicontext)中的[getPromptAction](js-apis-arkui-UIContext.md#getpromptaction)方法获取当前UI上下文关联的[PromptAction](js-apis-arkui-UIContext.md#promptaction)对象。
796
797**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
798
799**系统能力:** SystemCapability.ArkUI.ArkUI.Full
800
801**参数:**
802
803| 参数名   | 类型   | 必填 | 说明                             |
804| -------- | ------ | ---- | -------------------------------- |
805| dialogId | number | 是   | openCustomDialog返回的对话框id。 |
806
807**错误码:**
808
809以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.promptAction(弹窗)](errorcode-promptAction.md)错误码。
810
811| 错误码ID | 错误信息                           |
812| -------- | ---------------------------------- |
813| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
814| 100001   | Internal error. |
815
816**示例:**
817
818示例请看[promptAction.openCustomDialog](#promptactionopencustomdialogdeprecated)的示例。
819
820## ShowToastOptions
821
822文本提示框的选项。
823
824**系统能力:**  SystemCapability.ArkUI.ArkUI.Full
825
826| 名称                    | 类型                                                         | 必填 | 说明                                                         |
827| ----------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
828| message                 | string&nbsp;\|&nbsp;[Resource](arkui-ts/ts-types.md#resource类型) | 是   | 显示的文本信息。<br>**说明:** <br/>默认字体为'Harmony Sans',不支持设置其他字体。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
829| duration                | number                                                       | 否   | 默认值1500ms,取值区间:1500ms-10000ms。若小于1500ms则取默认值,若大于10000ms则取上限值10000ms。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
830| bottom                  | string&nbsp;\|&nbsp;number                                   | 否   | 设置弹窗底部边框距离导航条的高度,ToastShowMode.TOP_MOST模式下,软键盘拉起时,如果bottom值过小,toast要被软键盘遮挡时,会自动避让至距离软键盘80vp处。ToastShowMode.DEFAULT模式下,软键盘拉起时,会上移软键盘的高度。<br/>默认值:80vp<br/>**说明:** <br/>当底部没有导航条时,bottom为设置弹窗底部边框距离窗口底部的高度。<br/>设置对齐方式alignment后,bottom不生效。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
831| showMode<sup>11+</sup>  | [ToastShowMode](#toastshowmode11)                            | 否   | 设置弹窗是否显示在应用之上。<br>默认值:ToastShowMode.DEFAULT,默认显示在应用内。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
832| alignment<sup>12+</sup> | [Alignment](arkui-ts/ts-appendix-enums.md#alignment)         | 否   | 对齐方式。<br/>默认值:undefined,默认底部偏上位置。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。         |
833| offset<sup>12+</sup>    | [Offset](arkui-ts/ts-types.md#offset)                        | 否   | 在对齐方式上的偏移。<br/>默认值:{ dx: 0, dy: 0 },默认没有偏移。<br/>**说明:** <br/>只支持设置px类型的数值,如需设置vp,可以将vp改成px传入。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
834| backgroundColor<sup>12+</sup>    | [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | 否   | 文本提示框背板颜色。<br/>默认值:Color.Transparent<br/>**说明:** <br/>当设置了backgroundColor为非透明色时,backgroundBlurStyle需要设置为BlurStyle.NONE,否则颜色显示将不符合预期效果。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
835| textColor<sup>12+</sup>    | [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | 否   | 文本提示框文本颜色。<br/>默认值:Color.Black<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
836| backgroundBlurStyle<sup>12+</sup>    | [BlurStyle](arkui-ts/ts-universal-attributes-background.md#blurstyle9) | 否   | 文本提示框背板模糊材质。<br/>默认值:BlurStyle.COMPONENT_ULTRA_THICK<br/>**说明:** <br/>设置为BlurStyle.NONE即可关闭背景虚化。当设置了backgroundBlurStyle为非NONE值时,则不要设置backgroundColor,否则颜色显示将不符合预期效果。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
837| shadow<sup>12+</sup>    | [ShadowOptions](arkui-ts/ts-universal-attributes-image-effect.md#shadowoptions对象说明)&nbsp;\|&nbsp;[ShadowStyle](arkui-ts/ts-universal-attributes-image-effect.md#shadowstyle10枚举说明) | 否   | 文本提示框背板阴影。<br/>默认值:ShadowStyle.OUTER_DEFAULT_MD<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
838| enableHoverMode<sup>14+</sup>    | boolean                       | 否   | 是否响应悬停态。<br/>默认值:false,默认不响应。<br/>**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 |
839| hoverModeArea<sup>14+</sup> | [HoverModeAreaType](arkui-ts/ts-appendix-enums.md#hovermodeareatype14)         | 否   | 响应悬停态时,弹窗的显示区域。<br/>默认值:HoverModeAreaType.BOTTOM_SCREEN,默认显示在下半屏。<br/>**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。         |
840
841## ToastShowMode<sup>11+</sup>
842
843设置弹窗显示模式,默认显示在应用内,支持显示在应用之上。
844
845**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
846
847**系统能力:**  SystemCapability.ArkUI.ArkUI.Full
848
849| 名称     | 值   | 说明                   |
850| -------- | ---- | ---------------------- |
851| DEFAULT  | 0    | Toast 显示在应用内。   |
852| TOP_MOST | 1    | Toast 显示在应用之上。 |
853
854## ShowDialogOptions
855
856对话框的选项。
857
858**系统能力:** SystemCapability.ArkUI.ArkUI.Full
859
860| 名称                              | 类型                                                         | 必填 | 说明                                                         |
861| --------------------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
862| title                             | string&nbsp;\|&nbsp;[Resource](arkui-ts/ts-types.md#resource类型) | 否   | 标题文本。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
863| message                           | string&nbsp;\|&nbsp;[Resource](arkui-ts/ts-types.md#resource类型) | 否   | 内容文本。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
864| buttons                           | Array&lt;[Button](#button)&gt;                               | 否   | 对话框中按钮的数组,结构为:{text:'button',&nbsp;color:&nbsp;'\#666666'},支持大于1个按钮。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
865| alignment<sup>10+</sup>           | [DialogAlignment](arkui-ts/ts-methods-alert-dialog-box.md#dialogalignment枚举说明) | 否   | 弹窗在竖直方向上的对齐方式。<br/>默认值:DialogAlignment.Default<br/>**说明**:<br/>若在UIExtension中设置showInSubWindow为true, 弹窗将基于UIExtension的宿主窗口对齐。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
866| offset<sup>10+</sup>              | [Offset](arkui-ts/ts-types.md#offset)                        | 否   | 弹窗相对alignment所在位置的偏移量。<br/>默认值:{&nbsp;dx:&nbsp;0&nbsp;,&nbsp;dy:&nbsp;0&nbsp;}<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
867| maskRect<sup>10+</sup>            | [Rectangle](arkui-ts/ts-methods-alert-dialog-box.md#rectangle8类型说明) | 否   | 弹窗遮蔽层区域,在遮蔽层区域内的事件不透传,在遮蔽层区域外的事件透传。<br/>默认值:{ x: 0, y: 0, width: '100%', height: '100%' } <br/>**说明:**<br/>showInSubWindow为true时,maskRect不生效。<br/>maskRect在设置部分属性值后,其余属性值默认为0。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
868| showInSubWindow<sup>11+</sup>     | boolean                                                      | 否   | 某弹框需要显示在主窗口之外时,是否在子窗口显示此弹窗。<br/>默认值:false,弹窗显示在应用内,而非独立子窗口。<br/>**说明**:showInSubWindow为true的弹窗无法触发显示另一个showInSubWindow为true的弹窗。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
869| isModal<sup>11+</sup>             | boolean                                                      | 否   | 弹窗是否为模态窗口,模态窗口有蒙层,非模态窗口无蒙层。<br/>默认值:true,此时弹窗有蒙层。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
870| backgroundColor<sup>12+</sup>     | [ResourceColor](arkui-ts/ts-types.md#resourcecolor)          | 否   | 弹窗背板颜色。<br/>默认值:Color.Transparent<br/>**说明:** <br/>当设置了backgroundColor为非透明色时,backgroundBlurStyle需要设置为BlurStyle.NONE,否则颜色显示将不符合预期效果。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
871| backgroundBlurStyle<sup>12+</sup> | [BlurStyle](arkui-ts/ts-universal-attributes-background.md#blurstyle9) | 否   | 弹窗背板模糊材质。<br/>默认值:BlurStyle.COMPONENT_ULTRA_THICK<br/>**说明:** <br/>设置为BlurStyle.NONE即可关闭背景虚化。当设置了backgroundBlurStyle为非NONE值时,则不要设置backgroundColor,否则颜色显示将不符合预期效果。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
872| shadow<sup>12+</sup>              | [ShadowOptions](arkui-ts/ts-universal-attributes-image-effect.md#shadowoptions对象说明)&nbsp;\|&nbsp;[ShadowStyle](arkui-ts/ts-universal-attributes-image-effect.md#shadowstyle10枚举说明) | 否   | 设置弹窗背板的阴影。<br /> 当设备为2in1时,默认场景下获焦阴影值为ShadowStyle.OUTER_FLOATING_MD,失焦为ShadowStyle.OUTER_FLOATING_SM<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
873| enableHoverMode<sup>14+</sup>     | boolean                                                      | 否   | 是否响应悬停态。<br />默认值:false,默认不响应。<br/>**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。            |
874| hoverModeArea<sup>14+</sup>       | [HoverModeAreaType](arkui-ts/ts-appendix-enums.md#hovermodeareatype14) | 否   | 悬停态下弹窗默认展示区域。<br />默认值:HoverModeAreaType.BOTTOM_SCREEN<br/>**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 |
875| levelMode<sup>15+</sup>       | [LevelMode](#levelmode15枚举说明) | 否   | 设置弹窗显示层级。<br />**说明:**<br />- 默认值:LevelMode.OVERLAY<br />- 当且仅当showInSubWindow属性设置为false时生效。<br/>**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 |
876| levelUniqueId<sup>15+</sup>       | number | 否   | 设置页面级弹窗需要显示的层级下的[节点 uniqueId](js-apis-arkui-frameNode.md#getuniqueid12)。<br />**说明:**<br />- 当且仅当levelMode属性设置为LevelMode.EMBEDDED时生效。<br/>**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。|
877| immersiveMode<sup>15+</sup>       | [ImmersiveMode](#immersivemode15枚举说明) | 否   | 设置页面内弹窗蒙层效果。<br />**说明:**<br />- 默认值:ImmersiveMode.DEFAULT <br />- 当且仅当levelMode属性设置为LevelMode.EMBEDDED时生效。<br/>**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。|
878| levelOrder<sup>18+</sup>       | [LevelOrder](#levelorder18) | 否   | 设置弹窗显示的顺序。<br />**说明:**<br />- 默认值:LevelOrder.clamp(0) <br />- 不支持动态刷新顺序。<br/>**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。|
879
880## ShowDialogSuccessResponse
881
882对话框的响应结果。
883
884**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
885
886**系统能力:**  SystemCapability.ArkUI.ArkUI.Full
887
888| 名称  | 类型   | 必填 | 说明                            |
889| ----- | ------ | ---- | ------------------------------- |
890| index | number | 是   | 选中按钮在buttons数组中的索引。 |
891
892## ActionMenuOptions
893
894操作菜单的选项。
895
896**系统能力:** SystemCapability.ArkUI.ArkUI.Full
897
898| 名称                          | 类型                                                         | 必填 | 说明                                                         |
899| ----------------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
900| title                         | string&nbsp;\|&nbsp;[Resource](arkui-ts/ts-types.md#resource类型) | 否   | 标题文本。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
901| buttons                       | [[Button](#button),[Button](#button)?,[Button](#button)?,[Button](#button)?,[Button](#button)?,[Button](#button)?] | 是   | 菜单中菜单项按钮的数组,结构为:{text:'button',&nbsp;color:&nbsp;'\#666666'},支持1-6个按钮。按钮数量大于6个时,仅显示前6个按钮,之后的按钮不显示。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
902| showInSubWindow<sup>11+</sup> | boolean                                                      | 否   | 某弹框需要显示在主窗口之外时,是否在子窗口显示此弹窗。<br/>默认值:false,在子窗口不显示弹窗。<br/>**说明**:<br/> - showInSubWindow为true的弹窗无法触发显示另一个showInSubWindow为true的弹窗。 <br/> - 若在UIExtension中设置showInSubWindow为true, 弹窗将基于UIExtension的宿主窗口对齐。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
903| isModal<sup>11+</sup>         | boolean                                                      | 否   | 弹窗是否为模态窗口,模态窗口有蒙层,非模态窗口无蒙层。<br/>默认值:true,此时弹窗有蒙层。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
904| levelMode<sup>15+</sup>       | [LevelMode](#levelmode15枚举说明) | 否   | 设置弹窗显示层级。<br />**说明:**<br />- 默认值:LevelMode.OVERLAY。<br />- 当且仅当showInSubWindow属性设置为false时生效。<br/>**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。|
905| levelUniqueId<sup>15+</sup>       | number | 否   | 设置页面级弹窗需要显示的层级下的[节点 uniqueId](js-apis-arkui-frameNode.md#getuniqueid12)。<br />**说明:**<br />- 当且仅当levelMode属性设置为LevelMode.EMBEDDED时生效。<br/>**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。|
906| immersiveMode<sup>15+</sup>       | [ImmersiveMode](#immersivemode15枚举说明) | 否   | 设置页面内弹窗蒙层效果。<br />**说明:**<br />- 默认值:ImmersiveMode.DEFAULT <br />- 当且仅当levelMode属性设置为LevelMode.EMBEDDED时生效。<br/>**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。|
907
908## ActionMenuSuccessResponse
909
910操作菜单的响应结果。
911
912**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
913
914**系统能力:** SystemCapability.ArkUI.ArkUI.Full
915
916| 名称  | 类型   | 必填 | 说明                                     |
917| ----- | ------ | ---- | ---------------------------------------- |
918| index | number | 是   | 选中按钮在buttons数组中的索引,从0开始。 |
919
920## DialogController<sup>18+</sup>
921
922自定义弹窗控制器,继承自[CommonController](#commoncontroller18)。
923
924DialogController可作为UIContext弹出自定义弹窗的成员变量,具体用法可看[openCustomDialogWithController](js-apis-arkui-UIContext.md#opencustomdialogwithcontroller18)和[presentCustomDialog](js-apis-arkui-UIContext.md#presentcustomdialog18)示例。
925
926**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
927
928**系统能力:** SystemCapability.ArkUI.ArkUI.Full
929
930## CommonController<sup>18+</sup>
931
932公共控制器,可以控制promptAction相关组件。
933
934**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
935
936**系统能力:** SystemCapability.ArkUI.ArkUI.Full
937
938### constructor
939constructor()
940
941**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
942
943**系统能力:** SystemCapability.ArkUI.ArkUI.Full
944
945### close
946close(): void
947
948关闭显示的自定义弹窗,若已关闭,则不生效。
949
950**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
951
952**系统能力:** SystemCapability.ArkUI.ArkUI.Full
953
954## LevelOrder<sup>18+</sup>
955
956弹窗层级,可以控制弹窗显示的顺序。
957
958**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
959
960**系统能力:** SystemCapability.ArkUI.ArkUI.Full
961
962### clamp<sup>18+</sup>
963static clamp(order: number): LevelOrder
964
965创建指定顺序的弹窗层级。
966
967**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
968
969**系统能力:** SystemCapability.ArkUI.ArkUI.Full
970
971**参数:**
972
973| 参数名 | 类型    | 必填 | 说明                                                         |
974| ------ | ------- | ---- | ------------------------------------------------------------ |
975| order | number | 是   | 弹窗显示顺序。取值范围为[-100000.0, 100000.0],如果值小于-100000.0则设置为-100000.0,如果值大于100000.0则设置为100000.0。 |
976
977**返回值:**
978
979| 类型  | 说明    |
980| ------ | ------ |
981| [LevelOrder](#levelorder18) | 返回当前对象实例。 |
982
983### getOrder<sup>18+</sup>
984getOrder(): number
985
986获取弹窗显示顺序。
987
988**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
989
990**系统能力:** SystemCapability.ArkUI.ArkUI.Full
991
992**返回值:**
993
994| 类型  | 说明    |
995| ------ | ------ |
996| number | 返回显示顺序数值。 |
997
998## DialogOptions<sup>18+</sup>
999
1000自定义弹窗的内容,继承自[BaseDialogOptions](#basedialogoptions11)。
1001
1002**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
1003
1004**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1005
1006| 名称    | 类型                                                    | 必填 | 说明                                                         |
1007| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
1008| backgroundColor | [ResourceColor](arkui-ts/ts-types.md#resourcecolor)  | 否 | 设置弹窗背板颜色。<br/>默认值:Color.Transparent<br/>**说明:** <br/>当设置了backgroundColor为非透明色时,backgroundBlurStyle需要设置为BlurStyle.NONE,否则颜色显示将不符合预期效果。 |
1009| cornerRadius | [DialogOptionsCornerRadius](#dialogoptionscornerradius18) | 否 | 设置弹窗背板的圆角半径。<br />可分别设置4个圆角的半径。<br />默认值:{ topLeft: '32vp', topRight: '32vp', bottomLeft: '32vp', bottomRight: '32vp' }<br /> 圆角大小受组件尺寸限制,最大值为组件宽或高的一半,若值为负,则按照默认值处理。 <br /> 百分比参数方式:以父元素弹窗宽和高的百分比来设置弹窗的圆角。|
1010| borderWidth | [DialogOptionsBorderWidth](#dialogoptionsborderwidth18) | 否 | 设置弹窗背板的边框宽度。<br />可分别设置4个边框宽度。<br />默认值:0。<br /> 百分比参数方式:以父元素弹窗宽的百分比来设置弹窗的边框宽度。<br />当弹窗左边框和右边框大于弹窗宽度,弹窗上边框和下边框大于弹窗高度,显示可能不符合预期。|
1011| borderColor | [DialogOptionsBorderColor](#dialogoptionsbordercolor18) | 否 | 设置弹窗背板的边框颜色。<br/>默认值:Color.Black。<br/> 如果使用borderColor属性,需要和borderWidth属性一起使用。 |
1012| borderStyle | [DialogOptionsBorderStyle](#dialogoptionsborderstyle18) | 否 | 设置弹窗背板的边框样式。<br/>默认值:BorderStyle.Solid。<br/> 如果使用borderStyle属性,需要和borderWidth属性一起使用。 |
1013| width | [Dimension](arkui-ts/ts-types.md#dimension10) | 否   | 设置弹窗背板的宽度。<br />**说明:**<br>- 弹窗宽度默认最大值:400vp。<br />- 百分比参数方式:弹窗参考宽度为所在窗口的宽度,在此基础上调小或调大。|
1014| height | [Dimension](arkui-ts/ts-types.md#dimension10)  | 否   | 设置弹窗背板的高度。<br />**说明:**<br />- 弹窗高度默认最大值:0.9 *(窗口高度 - 安全区域)。<br />- 百分比参数方式:弹窗参考高度为(窗口高度 - 安全区域),在此基础上调小或调大。|
1015| shadow | [DialogOptionsShadow](#dialogoptionsshadow18) | 否 | 设置弹窗背板的阴影。<br />当设备为2in1时,默认场景下获焦阴影值为ShadowStyle.OUTER_FLOATING_MD,失焦为ShadowStyle.OUTER_FLOATING_SM |
1016| backgroundBlurStyle | [BlurStyle](arkui-ts/ts-universal-attributes-background.md#blurstyle9)                 | 否   | 弹窗背板模糊材质。<br/>默认值:BlurStyle.COMPONENT_ULTRA_THICK<br/>**说明:** <br/>设置为BlurStyle.NONE即可关闭背景虚化。当设置了backgroundBlurStyle为非NONE值时,则不要设置backgroundColor,否则颜色显示将不符合预期效果。 |
1017
1018## DialogOptionsCornerRadius<sup>18+</sup>
1019
1020type DialogOptionsCornerRadius = Dimension&nbsp;\|&nbsp;BorderRadiuses
1021
1022表示弹窗背板的圆角半径允许的数据字段类型。
1023
1024**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
1025
1026**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1027
1028| 类型                                                         | 说明                         |
1029| ------------------------------------------------------------ | ---------------------------- |
1030| [Dimension](arkui-ts/ts-types.md#dimension10) | 表示值类型为长度类型,用于描述尺寸单位。 |
1031| [BorderRadiuses](arkui-ts/ts-types.md#borderradiuses9) | 表示值类型为圆角类型,用于描述组件边框圆角半径。 |
1032
1033## DialogOptionsBorderWidth<sup>18+</sup>
1034
1035type DialogOptionsBorderWidth = Dimension&nbsp;\|&nbsp;EdgeWidths
1036
1037表示弹窗背板的边框宽度允许的数据字段类型。
1038
1039**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
1040
1041**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1042
1043| 类型                                                         | 说明                         |
1044| ------------------------------------------------------------ | ---------------------------- |
1045| [Dimension](arkui-ts/ts-types.md#dimension10) | 表示值类型为长度类型,用于描述尺寸单位。 |
1046| [EdgeWidths](arkui-ts/ts-types.md#edgewidths9) | 表示值类型为边框宽度类型,用于描述组件边框不同方向的宽度。 |
1047
1048## DialogOptionsBorderColor<sup>18+</sup>
1049
1050type DialogOptionsBorderColor = ResourceColor&nbsp;\|&nbsp;EdgeColors
1051
1052表示弹窗背板的边框颜色允许的数据字段类型。
1053
1054**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
1055
1056**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1057
1058| 类型                                                         | 说明                         |
1059| ------------------------------------------------------------ | ---------------------------- |
1060| [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | 表示值类型为颜色类型,用于描述资源颜色类型。 |
1061| [EdgeColors](arkui-ts/ts-types.md#edgecolors9) | 表示值类型为边框颜色,用于描述组件边框四条边的颜色。 |
1062
1063## DialogOptionsBorderStyle<sup>18+</sup>
1064
1065type DialogOptionsBorderStyle = BorderStyle&nbsp;\|&nbsp;EdgeStyles
1066
1067表示弹窗背板的边框样式允许的数据字段类型。
1068
1069**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
1070
1071**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1072
1073| 类型                                                         | 说明                         |
1074| ------------------------------------------------------------ | ---------------------------- |
1075| [BorderStyle](arkui-ts/ts-appendix-enums.md#borderstyle) | 表示值类型为边框类型,用于描述组件边框的类型。 |
1076| [EdgeStyles](arkui-ts/ts-types.md#edgestyles9) | 表示值类型为边框样式,用于描述组件边框四条边的样式。 |
1077
1078## DialogOptionsShadow<sup>18+</sup>
1079
1080type DialogOptionsShadow = ShadowOptions&nbsp;\|&nbsp;ShadowStyle
1081
1082表示弹窗背板的阴影允许的数据字段类型。
1083
1084**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
1085
1086**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1087
1088| 类型                                                         | 说明                         |
1089| ------------------------------------------------------------ | ---------------------------- |
1090| [ShadowOptions](arkui-ts/ts-universal-attributes-image-effect.md#shadowoptions对象说明) | 表示值类型为阴影属性集合,用于设置阴影的模糊半径、阴影的颜色、X轴和Y轴的偏移量。 |
1091| [ShadowStyle](arkui-ts/ts-universal-attributes-image-effect.md#shadowstyle10枚举说明) | 表示值类型为阴影类型,用于描述阴影的类型。 |
1092
1093## CustomDialogOptions<sup>11+</sup>
1094
1095自定义弹窗的内容,继承自[BaseDialogOptions](#basedialogoptions11)。
1096
1097**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1098
1099**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1100
1101| 名称    | 类型                                                    | 必填 | 说明                                                         |
1102| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
1103| builder | [CustomBuilder](arkui-ts/ts-types.md#custombuilder8) | 是  | 设置自定义弹窗的内容。<br/>**说明:** <br/>builder需要赋值为箭头函数,格式如下:() => { this.XXX() },其中XXX是内部builder名。<br/>如果是全局builder需要在组件内部创建一个builder,在内部builder中调用全局builder。<br/>builder根节点宽高百分比相对弹框容器大小。<br/>builder非根节点宽高百分比相对父节点大小。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
1104| backgroundColor <sup>12+</sup>| [ResourceColor](arkui-ts/ts-types.md#resourcecolor)  | 否 | 设置弹窗背板颜色。<br/>默认值:Color.Transparent<br/>**说明:** <br/>当设置了backgroundColor为非透明色时,backgroundBlurStyle需要设置为BlurStyle.NONE,否则颜色显示将不符合预期效果。 |
1105| cornerRadius<sup>12+</sup>| [Dimension](arkui-ts/ts-types.md#dimension10)&nbsp;\|&nbsp;[BorderRadiuses](arkui-ts/ts-types.md#borderradiuses9) | 否 | 设置背板的圆角半径。<br />可分别设置4个圆角的半径。<br />默认值:{ topLeft: '32vp', topRight: '32vp', bottomLeft: '32vp', bottomRight: '32vp' }<br /> 圆角大小受组件尺寸限制,最大值为组件宽或高的一半,若值为负,则按照默认值处理。 <br /> 百分比参数方式:以父元素弹窗宽和高的百分比来设置弹窗的圆角。|
1106| borderWidth<sup>12+</sup>| [Dimension](arkui-ts/ts-types.md#dimension10)&nbsp;\|&nbsp;[EdgeWidths](arkui-ts/ts-types.md#edgewidths9)  | 否 | 设置弹窗背板的边框宽度。<br />可分别设置4个边框宽度。<br />默认值:0<br /> 百分比参数方式:以父元素弹窗宽的百分比来设置弹窗的边框宽度。<br />当弹窗左边框和右边框大于弹窗宽度,弹窗上边框和下边框大于弹窗高度,显示可能不符合预期。 |
1107| borderColor<sup>12+</sup> | [ResourceColor](arkui-ts/ts-types.md#resourcecolor)&nbsp;\|&nbsp;[EdgeColors](arkui-ts/ts-types.md#edgecolors9)  | 否 | 设置弹窗背板的边框颜色。<br/>默认值:Color.Black<br/> 如果使用borderColor属性,需要和borderWidth属性一起使用。 |
1108| borderStyle<sup>12+</sup> | [BorderStyle](arkui-ts/ts-appendix-enums.md#borderstyle)&nbsp;\|&nbsp;[EdgeStyles](arkui-ts/ts-types.md#edgestyles9)  | 否 | 设置弹窗背板的边框样式。<br/>默认值:BorderStyle.Solid<br/> 如果使用borderStyle属性,需要和borderWidth属性一起使用。 |
1109| width<sup>12+</sup> | [Dimension](arkui-ts/ts-types.md#dimension10) | 否   | 设置弹窗背板的宽度。<br />**说明:**<br>- 弹窗宽度默认最大值:400vp。<br />- 百分比参数方式:弹窗参考宽度为所在窗口的宽度,在此基础上调小或调大。|
1110| height<sup>12+</sup> | [Dimension](arkui-ts/ts-types.md#dimension10)  | 否   | 设置弹窗背板的高度。<br />**说明:**<br />- 弹窗高度默认最大值:0.9 *(窗口高度 - 安全区域)。<br />- 百分比参数方式:弹窗参考高度为(窗口高度 - 安全区域),在此基础上调小或调大。|
1111| shadow<sup>12+</sup>| [ShadowOptions](arkui-ts/ts-universal-attributes-image-effect.md#shadowoptions对象说明)&nbsp;\|&nbsp;[ShadowStyle](arkui-ts/ts-universal-attributes-image-effect.md#shadowstyle10枚举说明)   | 否 | 设置弹窗背板的阴影。<br />当设备为2in1时,默认场景下获焦阴影值为ShadowStyle.OUTER_FLOATING_MD,失焦为ShadowStyle.OUTER_FLOATING_SM |
1112| backgroundBlurStyle<sup>12+</sup> | [BlurStyle](arkui-ts/ts-universal-attributes-background.md#blurstyle9)                 | 否   | 弹窗背板模糊材质。<br/>默认值:BlurStyle.COMPONENT_ULTRA_THICK<br/>**说明:** <br/>设置为BlurStyle.NONE即可关闭背景虚化。当设置了backgroundBlurStyle为非NONE值时,则不要设置backgroundColor,否则颜色显示将不符合预期效果。 |
1113
1114## BaseDialogOptions<sup>11+</sup>
1115
1116弹窗的选项。
1117
1118**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1119
1120| 名称            | 类型                                                         | 必填 | 说明                                                         |
1121| --------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1122| maskRect        | [Rectangle](arkui-ts/ts-methods-alert-dialog-box.md#rectangle8类型说明) | 否   | 弹窗遮蔽层区域。<br/>默认值:{ x: 0, y: 0, width: '100%', height: '100%' }<br/>**说明:**<br/>showInSubWindow为true时,maskRect不生效。<br/>maskRect在设置部分属性值后,其余属性值默认为0。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
1123| alignment       | [DialogAlignment](arkui-ts/ts-methods-alert-dialog-box.md#dialogalignment枚举说明) | 否   | 弹窗在竖直方向上的对齐方式。<br>默认值:DialogAlignment.Default <br/>**说明**:<br/>若在UIExtension中设置showInSubWindow为true, 弹窗将基于UIExtension的宿主窗口对齐。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
1124| offset          | [Offset](arkui-ts/ts-types.md#offset)                     | 否   | 弹窗相对alignment所在位置的偏移量。<br/>默认值:{&nbsp;dx:&nbsp;0&nbsp;,&nbsp;dy:&nbsp;0&nbsp;} <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
1125| isModal         | boolean                                                      | 否   | 弹窗是否为模态窗口,模态窗口有蒙层,非模态窗口无蒙层。<br/>默认值:true,此时弹窗有蒙层。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
1126| showInSubWindow | boolean                                                      | 否   | 某弹框需要显示在主窗口之外时,是否在子窗口显示此弹窗。<br/>默认值:false,弹窗显示在应用内,而非独立子窗口。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
1127| onWillDismiss<sup>12+</sup> | Callback<[DismissDialogAction](#dismissdialogaction12)> | 否 | 交互式关闭回调函数。<br/>**说明:**<br/>1.当用户执行点击遮障层关闭、左滑/右滑、三键back、键盘ESC关闭交互操作时,如果注册该回调函数,则不会立刻关闭弹窗。在回调函数中可以通过reason得到阻拦关闭弹窗的操作类型,从而根据原因选择是否能关闭弹窗。当前组件返回的reason中,暂不支持CLOSE_BUTTON的枚举值。<br/>2.在onWillDismiss回调中,不能再做onWillDismiss拦截。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
1128|  autoCancel<sup>12+</sup> |       boolean                                   | 否   | 点击遮障层时,是否关闭弹窗,true表示关闭弹窗。false表示不关闭弹窗。<br/>默认值:true <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
1129|  maskColor<sup>12+</sup> |        [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | 否    | 自定义蒙层颜色。<br>默认值: 0x33000000              <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
1130| transition<sup>12+</sup>          | [TransitionEffect](arkui-ts/ts-transition-animation-component.md#transitioneffect10) | 否   | 设置弹窗显示和退出的过渡效果。<br/>**说明:**<br/> 1.如果不设置,则使用默认的显示/退出动效。<br/> 2.显示动效中按back键,打断显示动效,执行退出动效,动画效果为显示动效与退出动效的曲线叠加后的效果。<br/> 3.退出动效中按back键,不会打断退出动效,退出动效继续执行,继续按back键退出应用。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
1131| onDidAppear<sup>12+</sup> | () => void | 否 | 弹窗弹出时的事件回调。<br />**说明:**<br />1.正常时序依次为:onWillAppear>>onDidAppear>>(onDateAccept/onCancel/onDateChange)>>onWillDisappear>>onDidDisappear。<br />2.在onDidAppear内设置改变弹窗显示效果的回调事件,二次弹出生效。<br />3.快速点击弹出,消失弹窗时,存在onWillDisappear在onDidAppear前生效。<br />4. 当弹窗入场动效未完成时关闭弹窗,该回调不会触发。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
1132| onDidDisappear<sup>12+</sup> | () => void | 否 | 弹窗消失时的事件回调。<br />**说明:**<br />正常时序依次为:onWillAppear>>onDidAppear>>(onDateAccept/onCancel/onDateChange)>>onWillDisappear>>onDidDisappear。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
1133| onWillAppear<sup>12+</sup> | () => void | 否 | 弹窗显示动效前的事件回调。<br />**说明:**<br />1.正常时序依次为:onWillAppear>>onDidAppear>>(onDateAccept/onCancel/onDateChange)>>onWillDisappear>>onDidDisappear。<br />2.在onWillAppear内设置改变弹窗显示效果的回调事件,二次弹出生效。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
1134| onWillDisappear<sup>12+</sup> | () => void | 否 | 弹窗退出动效前的事件回调。<br />**说明:**<br />1.正常时序依次为:onWillAppear>>onDidAppear>>(onDateAccept/onCancel/onDateChange)>>onWillDisappear>>onDidDisappear。<br />2.快速点击弹出,消失弹窗时,存在onWillDisappear在onDidAppear前生效。 <br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
1135| keyboardAvoidMode<sup>12+</sup> | [KeyboardAvoidMode](./arkui-ts/ts-types.md#keyboardavoidmode12枚举说明) | 否 | 用于设置弹窗是否在拉起软键盘时进行自动避让。<br/>默认值:KeyboardAvoidMode.DEFAULT<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
1136| enableHoverMode<sup>14+</sup>   | boolean | 否   | 是否响应悬停态。<br />默认值:false,默认不响应。<br/>**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。|
1137| hoverModeArea<sup>14+</sup>     | [HoverModeAreaType](arkui-ts/ts-appendix-enums.md#hovermodeareatype14) | 否   | 悬停态下弹窗默认展示区域。<br />默认值:HoverModeAreaType.BOTTOM_SCREEN<br/>**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 |
1138| keyboardAvoidDistance<sup>15+</sup>       | [LengthMetrics](js-apis-arkui-graphics.md#lengthmetrics12) | 否   | 弹窗避让键盘后,和键盘之间距离。<br />**说明:**<br/>- 默认值:16vp<br />- 默认单位:vp<br />- 当且仅当keyboardAvoidMode属性设置为DEFAULT时生效。<br/>**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。 |
1139| levelMode<sup>15+</sup>       | [LevelMode](#levelmode15枚举说明) | 否   | 设置弹窗显示层级。<br />**说明:**<br />- 默认值:LevelMode.OVERLAY。<br />- 当且仅当showInSubWindow属性设置为false时生效。<br/>**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。|
1140| levelUniqueId<sup>15+</sup>       | number | 否   | 设置页面级弹窗需要显示的层级下的[节点 uniqueId](js-apis-arkui-frameNode.md#getuniqueid12)。<br />**说明:**<br />- 当且仅当levelMode属性设置为LevelMode.EMBEDDED时生效。<br/>**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。|
1141| immersiveMode<sup>15+</sup>       | [ImmersiveMode](#immersivemode15枚举说明) | 否   | 设置页面内弹窗蒙层效果。<br />**说明:**<br />- 默认值:ImmersiveMode.DEFAULT <br />- 当且仅当levelMode属性设置为LevelMode.EMBEDDED时生效。<br/>**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。|
1142| levelOrder<sup>18+</sup>       | [LevelOrder](#levelorder18) | 否   | 设置弹窗显示的顺序。<br />**说明:**<br />- 默认值:LevelOrder.clamp(0) <br />- 不支持动态刷新顺序。<br/>**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。|
1143
1144## DismissDialogAction<sup>12+</sup>
1145
1146Dialog关闭的信息。
1147
1148**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1149
1150**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1151
1152### 属性
1153
1154| 名称    | 类型                                                         | 可读 | 可写 | 说明                                                         |
1155| ------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
1156| dismiss | Callback&lt;void&gt;                                         | 否   | 否   | Dialog关闭回调函数。开发者需要退出时调用,不需要退出时无需调用。 |
1157| reason  | [DismissReason](#dismissreason12枚举说明) | 否   | 否   | Dialog无法关闭原因。根据开发者需要选择不同操作下,Dialog是否需要关闭。 |
1158
1159## DismissReason<sup>12+</sup>枚举说明
1160
1161**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1162
1163**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1164
1165| 名称          | 值   | 描述                                                         |
1166| ------------- | ---- | ------------------------------------------------------------ |
1167| PRESS_BACK    | 0    | 点击三键back、左滑/右滑、键盘ESC。                           |
1168| TOUCH_OUTSIDE | 1    | 点击遮障层时。                                               |
1169| CLOSE_BUTTON  | 2    | 点击关闭按钮。                                               |
1170| SLIDE_DOWN    | 3    | 下拉关闭。<br/>**说明:** <br/>该接口仅支持在[半模态转场](./arkui-ts/ts-universal-attributes-sheet-transition.md)中使用。 |
1171
1172## LevelMode<sup>15+</sup>枚举说明
1173
1174弹窗显示层级模式。
1175
1176**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
1177
1178**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1179
1180| 名称    | 值   | 说明                                             |
1181| ------- | ---- | ------------------------------------------------ |
1182| OVERLAY | 0    | 弹窗层级为应用窗口根节点,应用内路由导航切换弹窗不隐藏。 |
1183| EMBEDDED    | 1    | 弹窗节点为页面内路由/导航下的节点,随路由导航切换,弹窗随页面隐藏。|
1184
1185## ImmersiveMode<sup>15+</sup>枚举说明
1186
1187页面内弹窗蒙层显示区域模式。
1188
1189**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
1190
1191**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1192
1193| 名称    | 值   | 说明                                             |
1194| ------- | ---- | ------------------------------------------------ |
1195| DEFAULT | 0    | 弹窗蒙层遵循父节点布局约束进行显示。 |
1196| EXTEND    | 1    | 弹窗蒙层可扩展至覆盖状态栏和导航条。
1197
1198## Button
1199
1200菜单中的菜单项按钮。
1201
1202**系统能力:** SystemCapability.ArkUI.ArkUI.Full
1203
1204| 名称    | 类型                                       | 必填   | 说明      |
1205| ----- | ---------------------------------------- | ---- | ------- |
1206| text  | string&nbsp;\|&nbsp; [Resource](arkui-ts/ts-types.md#resource类型) | 是    | 按钮文本内容。<br />**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
1207| color | string&nbsp;\| &nbsp;[Resource](arkui-ts/ts-types.md#resource类型) | 是    | 按钮文本颜色。<br />**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
1208| primary<sup>12+</sup> | boolean | 否    | 在弹窗获焦且未进行tab键走焦时,按钮是否默认响应Enter键。多个Button时,只允许一个Button的该字段配置为true,否则所有Button均不响应。多重弹窗可自动获焦连续响应。<br />**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |