W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
顯示警告彈窗組件,可設(shè)置文本內(nèi)容與響應(yīng)回調(diào)。
從API Version 7開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。
名稱 | 參數(shù)類型 | 參數(shù)描述 |
---|---|---|
show | AlertDialogParamWithConfirm | AlertDialogParamWithButtons | 定義并顯示AlertDialog組件。 |
參數(shù)名 | 參數(shù)類型 | 必填 | 參數(shù)描述 |
---|---|---|---|
title | ResourceStr | 否 | 彈窗標(biāo)題。 |
message | ResourceStr | 是 | 彈窗內(nèi)容。 |
autoCancel | boolean | 否 | 點(diǎn)擊遮障層時(shí),是否關(guān)閉彈窗。 默認(rèn)值:true |
confirm | { value: ResourceStr, fontColor?: ResourceColor, backgroundColor?: ResourceColor, action: () => void } | 否 | 確認(rèn)按鈕的文本內(nèi)容、文本色、按鈕背景色和點(diǎn)擊回調(diào)。 |
cancel | () => void | 否 | 點(diǎn)擊遮障層關(guān)閉dialog時(shí)的回調(diào)。 |
alignment | DialogAlignment | 否 | 彈窗在豎直方向上的對齊方式。 默認(rèn)值:DialogAlignment.Default |
offset | Offset | 否 | 彈窗相對alignment所在位置的偏移量。 |
gridCount | number | 否 | 彈窗容器寬度所占用柵格數(shù)。 |
參數(shù)名 | 參數(shù)類型 | 必填 | 參數(shù)描述 |
---|---|---|---|
title | ResourceStr | 否 | 彈窗標(biāo)題。 |
message | ResourceStr | 是 | 彈窗內(nèi)容。 |
autoCancel | boolean | 否 | 點(diǎn)擊遮障層時(shí),是否關(guān)閉彈窗。 默認(rèn)值:true |
primaryButton | { value: ResourceStr, fontColor?: ResourceColor, backgroundColor?: ResourceColor, action: () => void; } | 否 | 按鈕的文本內(nèi)容、文本色、按鈕背景色和點(diǎn)擊回調(diào)。 |
secondaryButton | { value: ResourceStr, fontColor?: ResourceColor, backgroundColor?: ResourceColor, action: () => void; } | 否 | 按鈕的文本內(nèi)容、文本色、按鈕背景色和點(diǎn)擊回調(diào)。 |
cancel | () => void | 否 | 點(diǎn)擊遮障層關(guān)閉dialog時(shí)的回調(diào)。 |
alignment | DialogAlignment | 否 | 彈窗在豎直方向上的對齊方式。 默認(rèn)值:DialogAlignment.Default |
offset | Offset | 否 | 彈窗相對alignment所在位置的偏移量。 |
gridCount | number | 否 | 彈窗容器寬度所占用柵格數(shù)。 |
名稱 | 描述 |
---|---|
Top | 垂直頂部對齊。 |
Center | 垂直居中對齊。 |
Bottom | 垂直底部對齊。 |
Default | 默認(rèn)對齊。 |
TopStart8+ | 左上對齊。 |
TopEnd8+ | 右上對齊。 |
CenterStart8+ | 左中對齊。 |
CenterEnd8+ | 右中對齊。 |
BottomStart8+ | 左下對齊。 |
BottomEnd8+ | 右下對齊。 |
- // xxx.ets
- @Entry
- @Component
- struct AlertDialogExample {
- build() {
- Column({ space: 5 }) {
- Button('one button dialog')
- .onClick(() => {
- AlertDialog.show(
- {
- title: 'title',
- message: 'text',
- autoCancel: true,
- alignment: DialogAlignment.Bottom,
- offset: { dx: 0, dy: -20 },
- gridCount: 3,
- confirm: {
- value: 'button',
- action: () => {
- console.info('Button-clicking callback')
- }
- },
- cancel: () => {
- console.info('Closed callbacks')
- }
- }
- )
- })
- .backgroundColor(0x317aff)
- Button('two button dialog')
- .onClick(() => {
- AlertDialog.show(
- {
- title: 'title',
- message: 'text',
- autoCancel: true,
- alignment: DialogAlignment.Bottom,
- gridCount: 4,
- offset: { dx: 0, dy: -20 },
- primaryButton: {
- value: 'cancel',
- action: () => {
- console.info('Callback when the first button is clicked')
- }
- },
- secondaryButton: {
- value: 'ok',
- action: () => {
- console.info('Callback when the second button is clicked')
- }
- },
- cancel: () => {
- console.info('Closed callbacks')
- }
- }
- )
- }).backgroundColor(0x317aff)
- }.width('100%').margin({ top: 5 })
- }
- }
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: