在线观看www成人影院-在线观看www日本免费网站-在线观看www视频-在线观看操-欧美18在线-欧美1级

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

ArkUI如何自定義彈窗(eTS)

ArkUI詳解 ? 來源:鴻蒙實驗室 ? 作者:鴻蒙實驗室 ? 2022-08-31 08:24 ? 次閱讀

自定義彈窗其實也是比較簡單的,通過CustomDialogController類就可以顯示自定義彈窗。

接下來我們通過代碼來看一下

大家也都用過@Entry,@Component等彈窗的話,只要用@CustomDialog就可以

先來預覽一下我實現的效果:

gif145gif

import

CustomDialogExample

from

'./customdialog'

?

@

Entry

@

Component

struct

Index

{

?

// 方式一:使用箭頭函數

onAccept

=

()

=>

{

console

.

info

(

'確定'

)

this

.

dialogController

.

close

();

}

dialogController

:

CustomDialogController

=

new

CustomDialogController

({

builder

:

CustomDialogExample

({

cancel

:

this

.

onCancel

,

confirm

:

this

.

onAccept

}),

?

alignment

:

DialogAlignment

.

Center

,

cancel

: ()

=>

{

console

.

log

(

"cancel"

)

// 點擊蒙層的回調

},

autoCancel

:

true

,

// 允許點擊蒙層關閉彈窗

customStyle

:

false

// 使用自定義樣式

})

?

onCancel

() {

console

.

info

(

'取消'

)

}

?

build

() {

Column

({}) {

Button

(

' 自定義彈窗'

)

.

onClick

(()

=>

{

//打開彈窗

this

.

dialogController

.

open

();

})

?

?

}.

width

(

"100%"

).

height

(

"100%"

).

alignItems

(

HorizontalAlign

.

Center

).

justifyContent

(

FlexAlign

.

Center

)

}

}

/*

* Copyright (c) 2021 JianGuo Device Co., Ltd.

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/

?

//通過CustomDialogController類顯示自定義彈窗。

@

CustomDialog

struct

CustomDialogExample

{

controller

:

CustomDialogController

cancel

: ()

=>

void

confirm

: ()

=>

void

?

build

() {

?

?

Flex

({

justifyContent

:

FlexAlign

.

Center

,

alignItems

:

ItemAlign

.

Center

,

alignContent

:

FlexAlign

.

Center

}) {

Button

(

'取消'

).

fontSize

(

36

)

.

onClick

(()

=>

{

//方式二:關閉彈窗

this

.

controller

.

close

()

this

.

cancel

()

}).

backgroundColor

(

0xffffff

).

fontColor

(

Color

.

Black

)

Button

(

'確定'

).

fontSize

(

36

)

.

onClick

(()

=>

{

// this.controller.close()

this

.

confirm

()

}).

backgroundColor

(

0xffffff

).

fontColor

(

Color

.

Red

)

}.

margin

({

bottom

:

10

}).

width

(

"100%"

).

height

(

200

)

}

?

}

export

default

CustomDialogExample

上面就是一個簡單的自定義彈窗

接下來看一下它的有關屬性

CustomDialogController 定義了 open()close() 方法,它們說明如下:

open:打開對話框,如果對話框已經打開,則再次打開無效。

close:關閉對話框,如果對話框已經關閉,則再次關閉無效。

value:創建控制器需要的配置參數

  • CustomDialogControllerOptions

說明如下:

builder:創建自定義彈窗的構造器。

cancel:點擊蒙層的事件回調。

autoCancel:是否允許點擊遮障層退出。

alignment:彈窗在豎直方向上的對齊方式。

offset:彈窗相對 alignment 所在位置的偏移量。

customStyle:彈窗容器樣式是否自定義。

源碼

declare interface CustomDialogControllerOptions {

/**

* Custom builder function.

* @since 7

*/

builder: any;

?

/**

* Defines the cancel function.

* @since 7

*/

cancel?: () => void;

?

/**

* Defines if use auto cancel when click on the outside of the dialog.

* @since 7

*/

autoCancel?: boolean;

?

/**

* Defines the dialog alignment of the screen.

* @since 7

*/

alignment?: DialogAlignment;

?

/**

* Defines the dialog offset.

* @since 7

*/

offset?: Offset;

?

/**

* Defines if use costom style.

* @since 7

*/

customStyle?: boolean;

?

/**

* Grid count of dialog.

* @since 8

*/

gridCount?: number;

}

DialogAlignment的位置

名稱 描述
Top 垂直頂部對齊。
Center 垂直居中對齊。
Bottom 垂直底部對齊。
Default 默認對齊。
TopStart8+ 左上對齊。
TopEnd8+ 右上對齊。
CenterStart8+ 左中對齊。
CenterEnd8+ 右中對齊。
BottomStart8+ 左下對齊。
BottomEnd8+ 右下對齊。

參考文檔

自定義彈窗

語法糖

審核編輯:湯梓紅
聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • Component
    +關注

    關注

    0

    文章

    13

    瀏覽量

    8874
  • OpenHarmony
    +關注

    關注

    25

    文章

    3722

    瀏覽量

    16313
收藏 人收藏

    評論

    相關推薦

    基于ArkUI eTS開發的堅果食譜(NutRecipes)

    基于ArkUI eTS開發的堅果食譜(NutRecipes)
    的頭像 發表于 08-18 08:23 ?1568次閱讀
    基于<b class='flag-5'>ArkUI</b> <b class='flag-5'>eTS</b>開發的堅果食譜(NutRecipes)

    HarmonyOS開發實例:【自定義Emitter】

    使用[Emitter]實現事件的訂閱和發布,使用[自定義彈窗]設置廣告信息。
    的頭像 發表于 04-14 11:37 ?1002次閱讀
    HarmonyOS開發實例:【<b class='flag-5'>自定義</b>Emitter】

    HarmonyOS開發案例:【彈窗使用】

    基于dialog和button組件,實現彈窗的幾種自定義效果
    的頭像 發表于 04-25 17:44 ?1383次閱讀
    HarmonyOS開發案例:【<b class='flag-5'>彈窗</b>使用】

    HarmonyOS開發案例:【 自定義彈窗

    基于ArkTS的聲明式開發范式實現了三種不同的彈窗,第一種直接使用公共組件,后兩種使用CustomDialogController實現自定義彈窗
    的頭像 發表于 05-16 18:18 ?1370次閱讀
    HarmonyOS開發案例:【 <b class='flag-5'>自定義</b><b class='flag-5'>彈窗</b>】

    OpenHarmony應用開發之自定義彈窗

    本文轉載自《OpenHarmony應用開發之自定義彈窗》,作者:zhushangyuan_ ? 應用場景 在應用的使用和開發中,彈窗是一個很常見的場景,自定義
    發表于 09-06 14:40

    OpenHarmony自定義組件介紹

    一、創建自定義組件 在ArkUI中,UI顯示的內容均為組件,由框架直接提供的稱為系統組件,由開發者定義的稱為自定義組件。在進行 UI 界面開發時,通常不是簡單的將系統組件進行組合使用,
    發表于 09-25 15:36

    1602自定義字符

    1602液晶能夠顯示自定義字符,能夠根據讀者的具體情況顯示自定義字符。
    發表于 01-20 15:43 ?1次下載

    三種自定義彈窗UI組件封裝的實現

    鴻蒙已經提供了全局 UI 方法自定義彈窗,本文是基于基礎的自定義彈窗來實現提示消息彈窗、確認彈窗
    的頭像 發表于 03-30 09:28 ?3156次閱讀

    自定義視圖組件教程案例

    自定義組件 1.自定義組件-particles(粒子效果) 2.自定義組件- pulse(脈沖button效果) 3.自定義組件-progress(progress效果) 4.
    發表于 04-08 10:48 ?14次下載

    labview自定義控件

    labview自定義精美控件
    發表于 05-15 16:46 ?17次下載

    在OpenHarmony上如何使用不同的彈窗

    應用中經常用到彈窗,比如警告彈窗、日期選擇彈窗、文本選擇彈窗以及其他自定義彈窗等等。
    的頭像 發表于 06-18 15:10 ?1144次閱讀
    在OpenHarmony上如何使用不同的<b class='flag-5'>彈窗</b>

    自定義算子開發

    一個完整的自定義算子應用過程包括注冊算子、算子實現、含自定義算子模型轉換和運行含自定義op模型四個階段。在大多數情況下,您的模型應該可以通過使用hb_mapper工具完成轉換并順利部署到地平線芯片上……
    的頭像 發表于 04-07 16:11 ?2811次閱讀
    <b class='flag-5'>自定義</b>算子開發

    labview超快自定義控件制作和普通自定義控件制作

    labview超快自定義控件制作和普通自定義控件制作
    發表于 08-21 10:32 ?13次下載

    鴻蒙ArkUI開發-應用添加彈窗

    彈窗是一種模態窗口,通常用來展示用戶當前需要的或用戶必須關注的信息或操作。在彈出框消失之前,用戶無法操作其他界面內容。ArkUI為我們提供了豐富的彈窗功能
    的頭像 發表于 01-24 17:22 ?663次閱讀
    鴻蒙<b class='flag-5'>ArkUI</b>開發-應用添加<b class='flag-5'>彈窗</b>

    鴻蒙ArkUI實例:【自定義組件】

    組件是 OpenHarmony 頁面最小顯示單元,一個頁面可由多個組件組合而成,也可只由一個組件組合而成,這些組件可以是ArkUI開發框架自帶系統組件,比如?`Text`?、?`Button`?等,也可以是自定義組件,本節筆者簡單介紹一下
    的頭像 發表于 04-08 10:17 ?642次閱讀
    主站蜘蛛池模板: 日韩毛片高清在线看 | 六月丁香婷婷激情 | 91久久国产青草亚洲 | 成年人视频黄色 | 日日草天天干 | 2021韩国理论片ok电影天堂 | 亚洲va中文字幕无码 | 欧美性猛| 三级色网站| 天天草天天 | 亚洲精品色图 | 女人本色高清在线观看wwwwww国产 | 久久综合九色综合97婷婷群聊 | 亚洲一级毛片中文字幕 | 午夜久久久 | 美女一级免费毛片 | 午夜毛片视频高清不卡免费 | 成人午夜性a一级毛片美女 成人午夜性视频欧美成人 成人小视频在线 | 欧美xxxx做受欧美88bbw | 爱爱免费视频 | 播放毛片| 一区二区高清在线观看 | 色偷偷中文字幕 | 好吊色7777sao在线视频观看 | 你懂得网址在线观看 | 中文字幕亚洲一区二区v@在线 | 日本视频www | 人人干综合 | 一区二区三区四区国产精品 | 天天操综 | 又粗又硬又大久久久 | 色456 | 四虎精品影院永久在线播放 | 亚洲免费成人 | 69国产视频| 日日噜噜爽爽狠狠视频 | 黄h视频在线观看视频 | 亚洲www美色| 黄色一级一毛片 | 亚洲人成电影在在线观看网色 | 天堂网www在线资源链接 |