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> 从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)对象。
14
15## 导入模块
16
17```ts
18import { promptAction } from '@kit.ArkUI';
19```
20
21## promptAction.showToast
22
23showToast(options: ShowToastOptions): void
24
25创建并显示文本提示框。
26
27**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
28
29**系统能力:** SystemCapability.ArkUI.ArkUI.Full
30
31**参数:**
32
33| 参数名     | 类型                                    | 必填   | 说明      |
34| ------- | ------------------------------------- | ---- | ------- |
35| options | [ShowToastOptions](#showtoastoptions) | 是    | 文本弹窗选项。 |
36
37**错误码:**
38
39以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.promptAction(弹窗)](errorcode-promptAction.md)错误码。
40
41| 错误码ID   | 错误信息 |
42| --------- | ------- |
43| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
44| 100001    | Internal error. |
45
46**示例:**
47
48```ts
49import { promptAction } from '@kit.ArkUI'
50import { BusinessError } from '@kit.BasicServicesKit';
51
52@Entry
53@Component
54struct toastExample {
55  build() {
56    Column() {
57      Button('Show toast').fontSize(20)
58        .onClick(() => {
59          try {
60            promptAction.showToast({
61              message: 'Hello World',
62              duration: 2000
63            });
64          } catch (error) {
65            let message = (error as BusinessError).message
66            let code = (error as BusinessError).code
67            console.error(`showToast args error code is ${code}, message is ${message}`);
68          };
69        })
70    }.height('100%').width('100%').justifyContent(FlexAlign.Center)
71  }
72}
73```
74API version 11及之前Toast样式。
75
76![zh-cn_image_0001](figures/toast-api11.gif)
77
78API version 12及之后Toast样式。
79
80![zh-cn_image_0001](figures/toast-api12.gif)
81
82## promptAction.openToast<sup>13+</sup>
83
84openToast(options: ShowToastOptions): Promise&lt;number&gt;
85
86显示文本提示框并返回文本提示框id。
87
88**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
89
90**系统能力:** SystemCapability.ArkUI.ArkUI.Full
91
92**参数**
93
94| 参数名  | 类型                                                         | 必填 | 说明           |
95| ------- | ------------------------------------------------------------ | ---- | -------------- |
96| options | [ShowToastOptions](#showtoastoptions) | 是   | 文本弹窗选项。 |
97
98**返回值**
99
100| 类型             | 说明                                 |
101| ---------------- | ------------------------------------ |
102| Promise&lt;number&gt; | 返回供closeToast使用的文本提示框id。 |
103
104**错误码:**
105
106以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.promptAction(弹窗)](errorcode-promptAction.md)错误码。
107
108| 错误码ID | 错误信息                                                     |
109| -------- | ------------------------------------------------------------ |
110| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. |
111| 100001   | Internal error.                                              |
112
113**示例:**
114
115```ts
116import { promptAction } from '@kit.ArkUI';
117import { BusinessError } from '@kit.BasicServicesKit';
118@Entry
119@Component
120struct toastExample {
121  @State toastId: number = 0;
122  build() {
123    Column() {
124      Button('Open Toast')
125        .height(100)
126        .onClick(() => {
127          try {
128            promptAction.openToast({
129              message: 'Toast Massage',
130              duration: 10000,
131            }).then((toastId: number) => {
132              this.toastId = toastId;
133            });
134          } catch (error) {
135            let message = (error as BusinessError).message;
136            let code = (error as BusinessError).code;
137            console.error(`OpenToast error code is ${code}, message is ${message}`);
138          };
139        })
140      Blank().height(50);
141      Button('Close Toast')
142        .height(100)
143        .onClick(() => {
144          try {
145            promptAction.closeToast(this.toastId);
146          } catch (error) {
147            let message = (error as BusinessError).message;
148            let code = (error as BusinessError).code;
149            console.error(`CloseToast error code is ${code}, message is ${message}`);
150          };
151        })
152    }.height('100%').width('100%').justifyContent(FlexAlign.Center)
153  }
154}
155```
156
157![toast-openclose](figures/toast-openclose.gif)
158
159## promptAction.closeToast<sup>13+</sup>
160
161closeToast(toastId: number): void
162
163关闭文本提示框。
164
165**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
166
167**系统能力:** SystemCapability.ArkUI.ArkUI.Full
168
169**参数**
170
171| 参数名  | 类型   | 必填 | 说明                          |
172| ------- | ------ | ---- | ----------------------------- |
173| toastId | number | 是   | openToast返回的文本提示框id。 |
174
175**错误码:**
176
177以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.promptAction(弹窗)](errorcode-promptAction.md)错误码。
178
179| 错误码ID | 错误信息                                                     |
180| -------- | ------------------------------------------------------------ |
181| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed. |
182| 100001   | Internal error.                                              |
183
184**示例:**
185
186示例请看[promptAction.openToaset13](#promptactionopentoast13)的示例。
187
188## promptAction.showDialog
189
190showDialog(options: ShowDialogOptions): Promise&lt;ShowDialogSuccessResponse&gt;
191
192创建并显示对话框,对话框响应后异步返回结果。
193
194**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
195
196**系统能力:**  SystemCapability.ArkUI.ArkUI.Full
197
198**参数:**
199
200| 参数名     | 类型                                      | 必填   | 说明     |
201| ------- | --------------------------------------- | ---- | ------ |
202| options | [ShowDialogOptions](#showdialogoptions) | 是    | 对话框选项。 |
203
204**返回值:**
205
206| 类型                                       | 说明       |
207| ---------------------------------------- | -------- |
208| Promise&lt;[ShowDialogSuccessResponse](#showdialogsuccessresponse)&gt; | 对话框响应结果。 |
209
210**错误码:**
211
212以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.promptAction(弹窗)](errorcode-promptAction.md)错误码。
213
214| 错误码ID   | 错误信息 |
215| --------- | ------- |
216| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
217| 100001    | Internal error. |
218
219**示例:**
220
221```ts
222import { promptAction } from '@kit.ArkUI'
223import { BusinessError } from '@kit.BasicServicesKit';
224
225try {
226  promptAction.showDialog({
227    title: 'Title Info',
228    message: 'Message Info',
229    buttons: [
230      {
231        text: 'button1',
232        color: '#000000'
233      },
234      {
235        text: 'button2',
236        color: '#000000'
237      }
238    ],
239  })
240    .then(data => {
241      console.info('showDialog success, click button: ' + data.index);
242    })
243    .catch((err:Error) => {
244      console.info('showDialog error: ' + err);
245    })
246} catch (error) {
247  let message = (error as BusinessError).message
248  let code = (error as BusinessError).code
249  console.error(`showDialog args error code is ${code}, message is ${message}`);
250};
251```
252
253![zh-cn_image_0002](figures/zh-cn_image_0002.gif)
254
255## promptAction.showDialog
256
257showDialog(options: ShowDialogOptions, callback: AsyncCallback&lt;ShowDialogSuccessResponse&gt;):void
258
259创建并显示对话框,对话框响应结果异步返回。
260
261**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
262
263**系统能力:**  SystemCapability.ArkUI.ArkUI.Full
264
265**参数:**
266
267| 参数名      | 类型                                       | 必填   | 说明           |
268| -------- | ---------------------------------------- | ---- | ------------ |
269| options  | [ShowDialogOptions](#showdialogoptions)  | 是    | 页面显示对话框信息描述。 |
270| callback | AsyncCallback&lt;[ShowDialogSuccessResponse](#showdialogsuccessresponse)&gt; | 是    | 对话框响应结果回调。   |
271
272**错误码:**
273
274以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.promptAction(弹窗)](errorcode-promptAction.md)错误码。
275
276| 错误码ID   | 错误信息 |
277| --------- | ------- |
278| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
279| 100001    | Internal error. |
280
281**示例:**
282
283```ts
284import { promptAction } from '@kit.ArkUI';
285import { BusinessError } from '@kit.BasicServicesKit';
286
287try {
288  promptAction.showDialog({
289    title: 'showDialog Title Info',
290    message: 'Message Info',
291    buttons: [
292      {
293        text: 'button1',
294        color: '#000000'
295      },
296      {
297        text: 'button2',
298        color: '#000000'
299      }
300    ]
301  }, (err, data) => {
302    if (err) {
303      console.info('showDialog err: ' + err);
304      return;
305    }
306    console.info('showDialog success callback, click button: ' + data.index);
307  });
308} catch (error) {
309  let message = (error as BusinessError).message
310  let code = (error as BusinessError).code
311  console.error(`showDialog args error code is ${code}, message is ${message}`);
312};
313```
314
315![zh-cn_image_0004](figures/zh-cn_image_0004.gif)
316
317当弹窗的showInSubWindow属性为true时,弹窗可显示在窗口外。
318
319```ts
320import { promptAction } from '@kit.ArkUI';
321import { BusinessError } from '@kit.BasicServicesKit';
322
323try {
324  promptAction.showDialog({
325    title: 'showDialog Title Info',
326    message: 'Message Info',
327    isModal: true,
328    showInSubWindow: true,
329    buttons: [
330      {
331        text: 'button1',
332        color: '#000000'
333      },
334      {
335        text: 'button2',
336        color: '#000000'
337      }
338    ]
339  }, (err, data) => {
340    if (err) {
341      console.info('showDialog err: ' + err);
342      return;
343    }
344    console.info('showDialog success callback, click button: ' + data.index);
345  });
346} catch (error) {
347  let message = (error as BusinessError).message
348  let code = (error as BusinessError).code
349  console.error(`showDialog args error code is ${code}, message is ${message}`);
350};
351```
352
353![zh-cn_image_0002_showinsubwindow](figures/zh-cn_image_0002_showinsubwindow.jpg)
354
355
356
357## promptAction.showActionMenu
358
359showActionMenu(options: ActionMenuOptions, callback: AsyncCallback&lt;ActionMenuSuccessResponse&gt;):void
360
361创建并显示操作菜单,菜单响应结果异步返回。
362
363**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
364
365**系统能力:** SystemCapability.ArkUI.ArkUI.Full366
367**参数:**
368
369| 参数名      | 类型                                       | 必填   | 说明        |
370| -------- | ---------------------------------------- | ---- | --------- |
371| options  | [ActionMenuOptions](#actionmenuoptions)  | 是    | 操作菜单选项。   |
372| callback | AsyncCallback&lt;[ActionMenuSuccessResponse](#actionmenusuccessresponse)> | 是    | 菜单响应结果回调。 |
373
374**错误码:**
375
376以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.promptAction(弹窗)](errorcode-promptAction.md)错误码。
377
378| 错误码ID   | 错误信息 |
379| --------- | ------- |
380| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
381| 100001    | Internal error. |
382
383**示例:**
384
385```ts
386import { promptAction } from '@kit.ArkUI';
387import { BusinessError } from '@kit.BasicServicesKit';
388
389try {
390  promptAction.showActionMenu({
391    title: 'Title Info',
392    buttons: [
393      {
394        text: 'item1',
395        color: '#666666'
396      },
397      {
398        text: 'item2',
399        color: '#000000'
400      },
401    ]
402  }, (err, data) => {
403    if (err) {
404      console.info('showActionMenu err: ' + err);
405      return;
406    }
407    console.info('showActionMenu success callback, click button: ' + data.index);
408  })
409} catch (error) {
410  let message = (error as BusinessError).message
411  let code = (error as BusinessError).code
412  console.error(`showActionMenu args error code is ${code}, message is ${message}`);
413};
414```
415
416![zh-cn_image_0005](figures/zh-cn_image_0005.gif)
417
418## promptAction.showActionMenu
419
420showActionMenu(options: ActionMenuOptions): Promise&lt;ActionMenuSuccessResponse&gt;
421
422创建并显示操作菜单,菜单响应后异步返回结果。
423
424**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
425
426**系统能力:** SystemCapability.ArkUI.ArkUI.Full
427
428**参数:**
429
430| 参数名     | 类型                                      | 必填   | 说明      |
431| ------- | --------------------------------------- | ---- | ------- |
432| options | [ActionMenuOptions](#actionmenuoptions) | 是    | 操作菜单选项。 |
433
434**返回值:**
435
436| 类型                                       | 说明      |
437| ---------------------------------------- | ------- |
438| Promise&lt;[ActionMenuSuccessResponse](#actionmenusuccessresponse)&gt; | 菜单响应结果。 |
439
440**错误码:**
441
442以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.promptAction(弹窗)](errorcode-promptAction.md)错误码。
443
444| 错误码ID   | 错误信息 |
445| --------- | ------- |
446| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
447| 100001    | Internal error. |
448
449**示例:**
450
451```ts
452import { promptAction } from '@kit.ArkUI';
453import { BusinessError } from '@kit.BasicServicesKit';
454
455try {
456  promptAction.showActionMenu({
457    title: 'showActionMenu Title Info',
458    buttons: [
459      {
460        text: 'item1',
461        color: '#666666'
462      },
463      {
464        text: 'item2',
465        color: '#000000'
466      },
467    ]
468  })
469    .then(data => {
470      console.info('showActionMenu success, click button: ' + data.index);
471    })
472    .catch((err:Error) => {
473      console.info('showActionMenu error: ' + err);
474    })
475} catch (error) {
476  let message = (error as BusinessError).message
477  let code = (error as BusinessError).code
478  console.error(`showActionMenu args error code is ${code}, message is ${message}`);
479};
480```
481
482![zh-cn_image_0006](figures/zh-cn_image_0006.gif)
483
484## promptAction.openCustomDialog<sup>11+</sup>
485
486openCustomDialog(options: CustomDialogOptions): Promise&lt;number&gt;
487
488打开自定义弹窗。
489
490<!--Del-->不支持在ServiceExtension中使用。<!--DelEnd-->
491
492暂不支持isModal = true与showInSubWindow = true同时使用。
493
494弹窗宽度在设备竖屏时默认为 所在窗口宽度 - 左右margin(16vp,设备为2in1时为40vp),最大默认宽度为400vp。
495
496**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
497
498**系统能力:** SystemCapability.ArkUI.ArkUI.Full
499
500**参数:**
501
502| 参数名  | 类型                                          | 必填 | 说明               |
503| ------- | --------------------------------------------- | ---- | ------------------ |
504| options | [CustomDialogOptions](#customdialogoptions11) | 是   | 自定义弹窗的内容。 |
505
506**返回值:**
507
508| 类型                  | 说明                                  |
509| --------------------- | ------------------------------------- |
510| Promise&lt;number&gt; | 返回供closeCustomDialog使用的对话框id。 |
511
512**错误码:**
513
514以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.promptAction(弹窗)](errorcode-promptAction.md)错误码。
515
516| 错误码ID | 错误信息                           |
517| -------- | ---------------------------------- |
518| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
519| 100001   | Internal error. |
520
521**示例:**
522
523```ts
524import { promptAction } from '@kit.ArkUI'
525
526@Entry
527@Component
528struct Index {
529  private customDialogComponentId: number = 0
530
531  @Builder customDialogComponent() {
532    Column() {
533      Text('弹窗').fontSize(30)
534      Row({ space: 50 }) {
535        Button("确认").onClick(() => {
536          promptAction.closeCustomDialog(this.customDialogComponentId)
537        })
538        Button("取消").onClick(() => {
539          promptAction.closeCustomDialog(this.customDialogComponentId)
540        })
541      }
542    }.height(200).padding(5).justifyContent(FlexAlign.SpaceBetween)
543  }
544
545  build() {
546    Row() {
547      Column({ space: 20 }) {
548        Text('组件内弹窗')
549          .fontSize(30)
550          .onClick(() => {
551            promptAction.openCustomDialog({
552              builder: () => {
553                this.customDialogComponent()
554              },
555              onWillDismiss: (dismissDialogAction: DismissDialogAction) => {
556                console.info("reason" + JSON.stringify(dismissDialogAction.reason))
557                console.log("dialog onWillDismiss")
558                if (dismissDialogAction.reason == DismissReason.PRESS_BACK) {
559                  dismissDialogAction.dismiss()
560                }
561                if (dismissDialogAction.reason == DismissReason.TOUCH_OUTSIDE) {
562                  dismissDialogAction.dismiss()
563                }
564              }
565            }).then((dialogId: number) => {
566              this.customDialogComponentId = dialogId
567            })
568          })
569      }
570      .width('100%')
571    }
572    .height('100%')
573  }
574}
575
576```
577该示例定义了弹窗样式,如宽度、高度、背景色、阴影等等。
578```ts
579import { promptAction } from '@kit.ArkUI'
580
581let customDialogId: number = 0
582
583@Builder
584function customDialogBuilder() {
585  Column() {
586    Text('Custom dialog Message').fontSize(10)
587    Row() {
588      Button("确认").onClick(() => {
589        promptAction.closeCustomDialog(customDialogId)
590      })
591      Blank().width(50)
592      Button("取消").onClick(() => {
593        promptAction.closeCustomDialog(customDialogId)
594      })
595    }
596  }
597}
598
599@Entry
600@Component
601struct Index {
602  @State message: string = 'Hello World'
603
604  @Builder
605  customDialogComponent() {
606    customDialogBuilder()
607  }
608
609  build() {
610    Row() {
611      Column() {
612        Text(this.message)
613          .fontSize(50)
614          .fontWeight(FontWeight.Bold)
615          .onClick(() => {
616            promptAction.openCustomDialog({
617              builder: () => {
618                this.customDialogComponent()
619              },
620              keyboardAvoidMode: KeyboardAvoidMode.NONE,
621              showInSubWindow: false,
622              offset: { dx: 5, dy: 5 },
623              backgroundColor: 0xd9ffffff,
624              cornerRadius: 20,
625              width: '80%',
626              height: 200,
627              borderWidth: 1,
628              borderStyle: BorderStyle.Dashed, //使用borderStyle属性,需要和borderWidth属性一起使用
629              borderColor: Color.Blue, //使用borderColor属性,需要和borderWidth属性一起使用
630              shadow: ({
631                radius: 20,
632                color: Color.Grey,
633                offsetX: 50,
634                offsetY: 0
635              }),
636            }).then((dialogId: number) => {
637              customDialogId = dialogId
638            })
639          })
640      }
641      .width('100%')
642    }
643    .height('100%')
644  }
645}
646```
647![zh-cn_image_0007](figures/zh-cn_image_0007.gif)
648
649## promptAction.closeCustomDialog<sup>11+</sup>
650
651closeCustomDialog(dialogId: number): void
652
653关闭自定义弹窗。
654
655**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
656
657**系统能力:** SystemCapability.ArkUI.ArkUI.Full
658
659**参数:**
660
661| 参数名   | 类型   | 必填 | 说明                             |
662| -------- | ------ | ---- | -------------------------------- |
663| dialogId | number | 是   | openCustomDialog返回的对话框id。 |
664
665**错误码:**
666
667以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.promptAction(弹窗)](errorcode-promptAction.md)错误码。
668
669| 错误码ID | 错误信息                           |
670| -------- | ---------------------------------- |
671| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameters types; 3. Parameter verification failed.   |
672| 100001   | Internal error. |
673
674**示例:**
675
676示例请看[promptAction.openCustomDialog](#promptactionopencustomdialog11)的示例。
677
678## ShowToastOptions
679
680文本提示框的选项。
681
682**系统能力:**  SystemCapability.ArkUI.ArkUI.Full
683
684| 名称                    | 类型                                                         | 必填 | 说明                                                         |
685| ----------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
686| message                 | string&nbsp;\|&nbsp;[Resource](arkui-ts/ts-types.md#resource类型) | 是   | 显示的文本信息。<br>**说明:** <br/>默认字体为'Harmony Sans',不支持设置其他字体。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
687| duration                | number                                                       | 否   | 默认值1500ms,取值区间:1500ms-10000ms。若小于1500ms则取默认值,若大于10000ms则取上限值10000ms。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
688| bottom                  | string&nbsp;\|&nbsp;number                                   | 否   | 设置弹窗底部边框距离导航条的高度,ToastShowMode.TOP_MOST模式下,软键盘拉起时,如果bottom值过小,toast要被软键盘遮挡时,会自动避让至距离软键盘80vp处。ToastShowMode.DEFAULT模式下,软键盘拉起时,会上移软键盘的高度。<br/>默认值:80vp<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
689| showMode<sup>11+</sup>  | [ToastShowMode](#toastshowmode11)                            | 否   | 设置弹窗是否显示在应用之上。<br>默认值:ToastShowMode.DEFAULT,默认显示在应用内。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
690| alignment<sup>12+</sup> | [Alignment](arkui-ts/ts-appendix-enums.md#alignment)         | 否   | 对齐方式。<br/>默认值:undefined,默认底部偏上位置。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。         |
691| offset<sup>12+</sup>    | [Offset](arkui-ts/ts-types.md#offset)                        | 否   | 在对齐方式上的偏移。<br/>默认值:{dx:0, dy:0},默认没有偏移。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
692| 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开始,该接口支持在原子化服务中使用。 |
693| textColor<sup>12+</sup>    | [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | 否   | 文本提示框文本颜色<br/>默认值:Color.Black<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
694| 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开始,该接口支持在原子化服务中使用。 |
695| 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.OuterDefaultMD<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
696| enableHoverMode<sup>13+</sup>    | boolean                       | 否   | 是否响应悬停态。<br/>默认值:False,默认不响应。<br/>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 |
697| hoverModeArea<sup>13+</sup> | [HoverModeAreaType](arkui-ts/ts-appendix-enums.md#hovermodeareatype13)         | 否   | 响应悬停态时,弹窗的显示区域。<br/>默认值:HoverModeAreaType.BOTTOM_SCREEN,默认显示在下半屏。<br/>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。         |
698
699## ToastShowMode<sup>11+</sup>
700
701设置弹窗显示模式,默认显示在应用内,支持显示在应用之上。
702
703**系统能力:**  SystemCapability.ArkUI.ArkUI.Full
704
705| 名称     | 值   | 说明                   |
706| -------- | ---- | ---------------------- |
707| DEFAULT  | 0    | Toast 显示在应用内。   |
708| TOP_MOST | 1    | Toast 显示在应用之上。 |
709
710## ShowDialogOptions
711
712对话框的选项。
713
714**系统能力:** SystemCapability.ArkUI.ArkUI.Full
715
716| 名称                              | 类型                                                         | 必填 | 说明                                                         |
717| --------------------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
718| title                             | string&nbsp;\|&nbsp;[Resource](arkui-ts/ts-types.md#resource类型) | 否   | 标题文本。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
719| message                           | string&nbsp;\|&nbsp;[Resource](arkui-ts/ts-types.md#resource类型) | 否   | 内容文本。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
720| buttons                           | Array&lt;[Button](#button)&gt;                               | 否   | 对话框中按钮的数组,结构为:{text:'button',&nbsp;color:&nbsp;'\#666666'},支持大于1个按钮。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
721| 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开始,该接口支持在原子化服务中使用。 |
722| 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开始,该接口支持在原子化服务中使用。 |
723| 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/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
724| showInSubWindow<sup>11+</sup>     | boolean                                                      | 否   | 某弹框需要显示在主窗口之外时,是否在子窗口显示此弹窗。<br/>默认值:false,弹窗显示在应用内,而非独立子窗口。<br/>**说明**:showInSubWindow为true的弹窗无法触发显示另一个showInSubWindow为true的弹窗。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
725| isModal<sup>11+</sup>             | boolean                                                      | 否   | 弹窗是否为模态窗口,模态窗口有蒙层,非模态窗口无蒙层。<br/>默认值:true,此时弹窗有蒙层。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
726| 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开始,该接口支持在原子化服务中使用。 |
727| 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开始,该接口支持在原子化服务中使用。 |
728| 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开始,该接口支持在原子化服务中使用。 |
729| enableHoverMode<sup>13+</sup>     | boolean                                                      | 否   | 是否响应悬停态。<br />默认值:false,默认不响应。            |
730| hoverModeArea<sup>13+</sup>       | [HoverModeAreaType](arkui-ts/ts-appendix-enums.md#hovermodeareatype13) | 否   | 悬停态下弹窗默认展示区域。<br />默认值:HoverModeAreaType.BOTTOM_SCREEN。 |
731
732## ShowDialogSuccessResponse
733
734对话框的响应结果。
735
736**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
737
738**系统能力:**  SystemCapability.ArkUI.ArkUI.Full
739
740| 名称  | 类型   | 必填 | 说明                            |
741| ----- | ------ | ---- | ------------------------------- |
742| index | number | 是   | 选中按钮在buttons数组中的索引。 |
743
744## ActionMenuOptions
745
746操作菜单的选项。
747
748**系统能力:** SystemCapability.ArkUI.ArkUI.Full
749
750| 名称                          | 类型                                                         | 必填 | 说明                                                         |
751| ----------------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
752| title                         | string&nbsp;\|&nbsp;[Resource](arkui-ts/ts-types.md#resource类型) | 否   | 标题文本。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
753| 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开始,该接口支持在原子化服务中使用。 |
754| showInSubWindow<sup>11+</sup> | boolean                                                      | 否   | 某弹框需要显示在主窗口之外时,是否在子窗口显示此弹窗。<br/>默认值:false,在子窗口不显示弹窗。<br/>**说明**:<br/> - showInSubWindow为true的弹窗无法触发显示另一个showInSubWindow为true的弹窗。 <br/> - 若在UIExtension中设置showInSubWindow为true, 弹窗将基于UIExtension的宿主窗口对齐。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
755| isModal<sup>11+</sup>         | boolean                                                      | 否   | 弹窗是否为模态窗口,模态窗口有蒙层,非模态窗口无蒙层。<br/>默认值:true,此时弹窗有蒙层。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
756
757## ActionMenuSuccessResponse
758
759操作菜单的响应结果。
760
761**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
762
763**系统能力:** SystemCapability.ArkUI.ArkUI.Full
764
765| 名称  | 类型   | 必填 | 说明                                     |
766| ----- | ------ | ---- | ---------------------------------------- |
767| index | number | 是   | 选中按钮在buttons数组中的索引,从0开始。 |
768
769## CustomDialogOptions<sup>11+</sup>
770
771自定义弹窗的内容,继承自[BaseDialogOptions](#basedialogoptions11)。
772
773**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
774
775**系统能力:** SystemCapability.ArkUI.ArkUI.Full
776
777| 名称    | 类型                                                    | 必填 | 说明                                                         |
778| ------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
779| 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开始,该接口支持在原子化服务中使用。 |
780| backgroundColor <sup>12+</sup>| [ResourceColor](arkui-ts/ts-types.md#resourcecolor)  | 否 | 设置弹窗背板颜色。<br/>默认值:Color.Transparent<br/>**说明:** <br/>当设置了backgroundColor为非透明色时,backgroundBlurStyle需要设置为BlurStyle.NONE,否则颜色显示将不符合预期效果。 |
781| 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 /> 百分比参数方式:以父元素弹窗宽和高的百分比来设置弹窗的圆角。|
782| 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 />当弹窗左边框和右边框大于弹窗宽度,弹窗上边框和下边框大于弹窗高度,显示可能不符合预期。|
783| 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属性一起使用。 |
784| 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属性一起使用。 |
785| width<sup>12+</sup> | [Dimension](arkui-ts/ts-types.md#dimension10) | 否   | 设置弹窗背板的宽度。<br />**说明:**<br>- 弹窗宽度默认最大值:400vp。<br />- 百分比参数方式:弹窗参考宽度为所在窗口的宽度,在此基础上调小或调大。|
786| height<sup>12+</sup> | [Dimension](arkui-ts/ts-types.md#dimension10)  | 否   | 设置弹窗背板的高度。<br />**说明:**<br />- 弹窗高度默认最大值:0.9 *(窗口高度 - 安全区域)。<br />- 百分比参数方式:弹窗参考高度为(窗口高度 - 安全区域),在此基础上调小或调大。|
787| 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 |
788| 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,否则颜色显示将不符合预期效果。 |
789
790## BaseDialogOptions<sup>11+</sup>
791
792弹窗的选项。
793
794**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
795
796**系统能力:** SystemCapability.ArkUI.ArkUI.Full
797
798| 名称            | 类型                                                         | 必填 | 说明                                                         |
799| --------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
800| 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不生效。 |
801| alignment       | [DialogAlignment](arkui-ts/ts-methods-alert-dialog-box.md#dialogalignment枚举说明) | 否   | 弹窗在竖直方向上的对齐方式。<br>默认值:DialogAlignment.Default <br/>**说明**:<br/>若在UIExtension中设置showInSubWindow为true, 弹窗将基于UIExtension的宿主窗口对齐。|
802| offset          | [Offset](arkui-ts/ts-types.md#offset)                     | 否   | 弹窗相对alignment所在位置的偏移量。<br/>默认值:{&nbsp;dx:&nbsp;0&nbsp;,&nbsp;dy:&nbsp;0&nbsp;} |
803| isModal         | boolean                                                      | 否   | 弹窗是否为模态窗口,模态窗口有蒙层,非模态窗口无蒙层。<br/>默认值:true,此时弹窗有蒙层。 |
804| showInSubWindow | boolean                                                      | 否   | 某弹框需要显示在主窗口之外时,是否在子窗口显示此弹窗。<br/>默认值:false,弹窗显示在应用内,而非独立子窗口。 |
805| onWillDismiss<sup>12+</sup> | Callback<[DismissDialogAction](#dismissdialogaction12)> | 否 | 交互式关闭回调函数。<br/>**说明:**<br/>1.当用户执行点击遮障层关闭、左滑/右滑、三键back、键盘ESC关闭交互操作时,如果注册该回调函数,则不会立刻关闭弹窗。在回调函数中可以通过reason得到阻拦关闭弹窗的操作类型,从而根据原因选择是否能关闭弹窗。当前组件返回的reason中,暂不支持CLOSE_BUTTON的枚举值。<br/>2.在onWillDismiss回调中,不能再做onWillDismiss拦截。 |
806|  autoCancel<sup>12+</sup> |       boolean                                   | 否   | 点击遮障层时,是否关闭弹窗,true表示关闭弹窗。false表示不关闭弹窗。<br/>默认值:true |
807|  maskColor<sup>12+</sup> |        [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | 否    | 自定义蒙层颜色。<br>默认值: 0x33000000              |
808| transition<sup>12+</sup>          | [TransitionEffect](arkui-ts/ts-transition-animation-component.md#transitioneffect10) | 否   | 设置弹窗显示和退出的过渡效果。<br/>**说明:**<br/> 1.如果不设置,则使用默认的显示/退出动效。<br/> 2.显示动效中按back键,打断显示动效,执行退出动效,动画效果为显示动效与退出动效的曲线叠加后的效果。<br/> 3.退出动效中按back键,不会打断退出动效,退出动效继续执行,继续按back键退出应用。                               |
809| onDidAppear<sup>12+</sup> | () => void | 否 | 弹窗弹出时的事件回调。<br />**说明:**<br />1.正常时序依次为:onWillAppear>>onDidAppear>>(onDateAccept/onCancel/onDateChange)>>onWillDisappear>>onDidDisappear。<br />2.在onDidAppear内设置改变弹窗显示效果的回调事件,二次弹出生效。<br />3.快速点击弹出,消失弹窗时,存在onWillDisappear在onDidAppear前生效。<br />4. 当弹窗入场动效未完成时关闭弹窗,该回调不会触发。 |
810| onDidDisappear<sup>12+</sup> | () => void | 否 | 弹窗消失时的事件回调。<br />**说明:**<br />正常时序依次为:onWillAppear>>onDidAppear>>(onDateAccept/onCancel/onDateChange)>>onWillDisappear>>onDidDisappear。 |
811| onWillAppear<sup>12+</sup> | () => void | 否 | 弹窗显示动效前的事件回调。<br />**说明:**<br />1.正常时序依次为:onWillAppear>>onDidAppear>>(onDateAccept/onCancel/onDateChange)>>onWillDisappear>>onDidDisappear。<br />2.在onWillAppear内设置改变弹窗显示效果的回调事件,二次弹出生效。 |
812| onWillDisappear<sup>12+</sup> | () => void | 否 | 弹窗退出动效前的事件回调。<br />**说明:**<br />1.正常时序依次为:onWillAppear>>onDidAppear>>(onDateAccept/onCancel/onDateChange)>>onWillDisappear>>onDidDisappear。<br />2.快速点击弹出,消失弹窗时,存在onWillDisappear在onDidAppear前生效。 |
813| keyboardAvoidMode<sup>12+</sup> | [KeyboardAvoidMode](#keyboardavoidmode12枚举说明) | 否 | 用于设置弹窗是否在拉起软键盘时进行自动避让。<br/>默认值:KeyboardAvoidMode.DEFAULT<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
814| enableHoverMode<sup>13+</sup>              | boolean | 否   | 是否响应悬停态。<br />默认值:false,默认不响应。|
815| hoverModeArea<sup>13+</sup>              | [HoverModeAreaType](arkui-ts/ts-appendix-enums.md#hovermodeareatype13) | 否   | 悬停态下弹窗默认展示区域。<br />默认值:HoverModeAreaType.BOTTOM_SCREEN。|
816
817## DismissDialogAction<sup>12+</sup>
818
819Dialog关闭的信息。
820
821**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
822
823**系统能力:** SystemCapability.ArkUI.ArkUI.Full
824
825### 属性
826
827| 名称    | 类型                                                         | 可读 | 可写 | 说明                                                         |
828| ------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
829| dismiss | Callback&lt;void&gt;                                         | 否   | 否   | Dialog关闭回调函数。开发者需要退出时调用,不需要退出时无需调用。 |
830| reason  | [DismissReason](#dismissreason12枚举说明) | 否   | 否   | Dialog无法关闭原因。根据开发者需要选择不同操作下,Dialog是否需要关闭。 |
831
832## DismissReason<sup>12+</sup>枚举说明
833
834**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
835
836**系统能力:** SystemCapability.ArkUI.ArkUI.Full
837
838| 名称          | 值   | 描述                                                         |
839| ------------- | ---- | ------------------------------------------------------------ |
840| PRESS_BACK    | 0    | 点击三键back、左滑/右滑、键盘ESC。                           |
841| TOUCH_OUTSIDE | 1    | 点击遮障层时。                                               |
842| CLOSE_BUTTON  | 2    | 点击关闭按钮。                                               |
843| SLIDE_DOWN    | 3    | 下拉关闭。<br/>**说明:** <br/>该接口仅支持在[半模态转场](./arkui-ts/ts-universal-attributes-sheet-transition.md)中使用。 |
844
845## KeyboardAvoidMode<sup>12+</sup>枚举说明
846
847**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
848
849**系统能力:** SystemCapability.ArkUI.ArkUI.Full
850
851| 名称    | 值   | 说明                                             |
852| ------- | ---- | ------------------------------------------------ |
853| DEFAULT | 0    | 默认避让软键盘并在到达极限高度之后进行高度压缩。 |
854| NONE    | 1    | 不避让软键盘。                                   |
855
856## Button
857
858菜单中的菜单项按钮。
859
860**系统能力:** SystemCapability.ArkUI.ArkUI.Full
861
862| 名称    | 类型                                       | 必填   | 说明      |
863| ----- | ---------------------------------------- | ---- | ------- |
864| text  | string&nbsp;\|&nbsp; [Resource](arkui-ts/ts-types.md#resource类型) | 是    | 按钮文本内容。<br />**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
865| color | string&nbsp;\| &nbsp;[Resource](arkui-ts/ts-types.md#resource类型) | 是    | 按钮文本颜色。<br />**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
866| primary<sup>12+</sup> | boolean | 否    | 在弹窗获焦且未进行tab键走焦时,按钮是否默认响应Enter键。多个Button时,只允许一个Button的该字段配置为true,否则所有Button均不响应。多重弹窗可自动获焦连续响应。<br />**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |