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

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

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

3天內(nèi)不再提示

ArkUI如何自定義彈窗(eTS)

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

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

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

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

先來預覽一下我實現(xiàn)的效果:

gif145gif

import

CustomDialogExample

from

'./customdialog'

?

@

Entry

@

Component

struct

Index

{

?

// 方式一:使用箭頭函數(shù)

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"

)

// 點擊蒙層的回調(diào)

},

autoCancel

:

true

,

// 允許點擊蒙層關(guān)閉彈窗

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

(()

=>

{

//方式二:關(guān)閉彈窗

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

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

接下來看一下它的有關(guān)屬性

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

open:打開對話框,如果對話框已經(jīng)打開,則再次打開無效。

close:關(guān)閉對話框,如果對話框已經(jīng)關(guān)閉,則再次關(guān)閉無效。

value:創(chuàng)建控制器需要的配置參數(shù),

  • CustomDialogControllerOptions

說明如下:

builder:創(chuàng)建自定義彈窗的構(gòu)造器。

cancel:點擊蒙層的事件回調(diào)。

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+ 右下對齊。

參考文檔

自定義彈窗

語法糖

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

    關(guān)注

    0

    文章

    13

    瀏覽量

    9000
  • OpenHarmony
    +關(guān)注

    關(guān)注

    28

    文章

    3841

    瀏覽量

    18269
收藏 人收藏

    評論

    相關(guān)推薦
    熱點推薦

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

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

    HarmonyOS開發(fā)實例:【自定義Emitter】

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

    HarmonyOS開發(fā)案例:【彈窗使用】

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

    HarmonyOS開發(fā)案例:【 自定義彈窗

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

    HarmonyOS應(yīng)用自定義鍵盤解決方案

    自定義鍵盤是一種替換系統(tǒng)默認鍵盤的解決方案,可實現(xiàn)鍵盤個性化交互。允許用戶結(jié)合業(yè)務(wù)需求與操作習慣,對按鍵布局進行可視化重構(gòu)、設(shè)置多功能組合鍵位,使輸入更加便捷和舒適。在安全防護層面,自定義鍵盤可以
    的頭像 發(fā)表于 06-05 14:19 ?480次閱讀

    OpenHarmony應(yīng)用開發(fā)之自定義彈窗

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

    1602自定義字符

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

    三種自定義彈窗UI組件封裝的實現(xiàn)

    鴻蒙已經(jīng)提供了全局 UI 方法自定義彈窗,本文是基于基礎(chǔ)的自定義彈窗來實現(xiàn)提示消息彈窗、確認彈窗
    的頭像 發(fā)表于 03-30 09:28 ?3545次閱讀

    自定義視圖組件教程案例

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

    labview自定義控件

    labview自定義精美控件
    發(fā)表于 05-15 16:46 ?18次下載

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

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

    自定義算子開發(fā)

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

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

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

    鴻蒙ArkUI開發(fā)-應(yīng)用添加彈窗

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

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

    組件是 OpenHarmony 頁面最小顯示單元,一個頁面可由多個組件組合而成,也可只由一個組件組合而成,這些組件可以是ArkUI開發(fā)框架自帶系統(tǒng)組件,比如?`Text`?、?`Button`?等,也可以是自定義組件,本節(jié)筆者簡單介紹一下
    的頭像 發(fā)表于 04-08 10:17 ?1021次閱讀
    主站蜘蛛池模板: 在线免费你懂的 | 色偷偷av男人的天堂 | 欧美三级 欧美一级 | 国产精品嫩草影院在线播放 | 久久天天躁夜夜躁狠狠85麻豆 | 免费网站你懂得 | 天天av天天翘天天综合网 | 一区二区三区网站在线免费线观看 | 成人a视频| 国产精品毛片久久久久久久 | 日本香蕉视频 | www.日日爱| 日韩在线视频www色 日韩在线视频免费观看 | 夜夜摸夜夜爽 | 色哟永久免费 | 国产高清一区二区三区 | 五月婷婷六月丁香激情 | 丁香九月婷婷 | h视频在线观看网站 | 亚洲精品美女在线观看 | 亚洲精品九色在线网站 | 四虎4hu | 91av在线视频观看 | 人人人人凹人人爽人人澡 | 亚州黄色网址 | 天堂中文在线网 | 人人操天天射 | 中文字幕一区在线播放 | 婷婷丁香五月中文字幕 | 一级片 在线播放 | 日日干天天爽 | 久久综合色区 | 亚欧色| 日本大片黄色 | 丁香婷婷激情五月 | 色狠狠综合 | 亚洲六月婷婷 | 欧美 变态 另类 人妖班 | 亚洲hh| 一区二区三区在线播放 | 中文字幕一区2区 |