W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
自定義彈窗(CustomDialog)可用于廣告、中獎、警告、軟件更新等與用戶交互響應操作。開發(fā)者可以通過CustomDialogController類顯示自定義彈窗。具體用法請參考自定義彈窗。
- @CustomDialog
- struct CustomDialogExample {
- controller: CustomDialogController
- build() {
- Column() {
- Text('我是內(nèi)容')
- .fontSize(20)
- .margin({ top: 10, bottom: 10 })
- }
- }
- }
- dialogController: CustomDialogController = new CustomDialogController({
- builder: CustomDialogExample({}),
- })
- Flex({justifyContent:FlexAlign.Center}){
- Button('click me')
- .onClick(() => {
- this.dialogController.open()
- })
- }.width('100%')
- @CustomDialog
- struct CustomDialogExample {
- controller: CustomDialogController
- cancel: () => void
- confirm: () => void
- build() {
- Column() {
- Text('我是內(nèi)容').fontSize(20).margin({ top: 10, bottom: 10 })
- Flex({ justifyContent: FlexAlign.SpaceAround }) {
- Button('cancel')
- .onClick(() => {
- this.controller.close()
- this.cancel()
- }).backgroundColor(0xffffff).fontColor(Color.Black)
- Button('confirm')
- .onClick(() => {
- this.controller.close()
- this.confirm()
- }).backgroundColor(0xffffff).fontColor(Color.Red)
- }.margin({ bottom: 10 })
- }
- }
- }
- dialogController: CustomDialogController = new CustomDialogController({
- builder: CustomDialogExample({
- cancel: this.onCancel,
- confirm: this.onAccept,
- }),
- alignment: DialogAlignment.Default, // 可設(shè)置dialog的對齊方式,設(shè)定顯示在底部或中間等,默認為底部顯示
- })
- onCancel() {
- console.info('Callback when the first button is clicked')
- }
- onAccept() {
- console.info('Callback when the second button is clicked')
- }
- // xxx.ets
- @CustomDialog
- struct CustomDialogExample {
- controller: CustomDialogController
- cancel: () => void
- confirm: () => void
- build() {
- Column() {
- Text('我是內(nèi)容').fontSize(20).margin({ top: 10, bottom: 10 })
- Flex({ justifyContent: FlexAlign.SpaceAround }) {
- Button('cancel')
- .onClick(() => {
- this.controller.close()
- this.cancel()
- }).backgroundColor(0xffffff).fontColor(Color.Black)
- Button('confirm')
- .onClick(() => {
- this.controller.close()
- this.confirm()
- }).backgroundColor(0xffffff).fontColor(Color.Red)
- }.margin({ bottom: 10 })
- }
- }
- }
- @Entry
- @Component
- struct DialogExample {
- dialogController: CustomDialogController = new CustomDialogController({
- builder: CustomDialogExample({
- cancel: this.onCancel,
- confirm: this.onAccept,
- }),
- alignment: DialogAlignment.Default, // 可設(shè)置dialog的對齊方式,設(shè)定顯示在底部或中間等,默認為底部顯示
- })
- onCancel() {
- console.info('Callback when the first button is clicked')
- }
- onAccept() {
- console.info('Callback when the second button is clicked')
- }
- build() {
- Flex({ justifyContent: FlexAlign.Center }) {
- Button('click me')
- .onClick(() => {
- this.dialogController.open()
- })
- }.width('100%')
- }
- }
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: