chinese直男口爆体育生外卖, 99久久er热在这里只有精品99, 又色又爽又黄18禁美女裸身无遮挡, gogogo高清免费观看日本电视,私密按摩师高清版在线,人妻视频毛茸茸,91论坛 兴趣闲谈,欧美 亚洲 精品 8区,国产精品久久久久精品免费

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

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

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

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

OpenHarmony技術(shù)社區(qū) ? 來源:OST開源開發(fā)者 ? 2023-06-18 15:10 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

應(yīng)用中經(jīng)常用到彈窗,比如警告彈窗、日期選擇彈窗、文本選擇彈窗以及其他自定義彈窗等等。本例將為大家介紹如何使用不同的彈窗。

效果呈現(xiàn)

本例最終效果如下:

83f5bbfe-0da6-11ee-962d-dac502259ad0.gif

示例中共涉及四類彈窗:

警告彈窗:提示信息尚未保存。

日期滑動(dòng)選擇器彈窗:選擇出生日期。

文本滑動(dòng)選擇器彈窗:選擇性別。

自定義彈窗:填寫興趣愛好。

說明:自定義彈窗可以根據(jù)業(yè)務(wù)需要自行定義彈窗的形式和內(nèi)容,比如文本輸入、單選、多選等等,本例以文本輸入為例進(jìn)行介紹。

運(yùn)行環(huán)境

本例基于以下環(huán)境開發(fā),開發(fā)者也可以基于其他適配的版本進(jìn)行開發(fā):

IDE:DevEco Studio 3.1 Release

SDK:Ohos_sdk_public 3.2.12.5(API Version 9 Release)

實(shí)現(xiàn)思路

本例中涉及的 4 類彈窗及實(shí)現(xiàn)方案如下:

警告彈窗:使用 AlertDialog 實(shí)現(xiàn)。

日期滑動(dòng)選擇器彈窗:使用 DatePickerDialog 實(shí)現(xiàn)。

文本滑動(dòng)選擇器彈窗:使用 TextPickerDialog 實(shí)現(xiàn)。

自定義彈窗:使用 CustomDialogController 實(shí)現(xiàn)。

開發(fā)步驟

由于本例重點(diǎn)講解對(duì)話框的使用,所以開發(fā)步驟會(huì)著重講解相關(guān)實(shí)現(xiàn),不相關(guān)的內(nèi)容不做介紹,全量代碼可參考完整代碼章節(jié)。

①首先,使用 AlertDialog 實(shí)現(xiàn)警告彈窗

通過 message 參數(shù)設(shè)置告警信息,alignment 設(shè)置彈窗在界面中垂直方向的對(duì)齊方式;通過 primaryButton 和 secondaryButton 添加按鈕。

具體代碼如下:

alertDialog(context:Context.UIAbilityContext){
AlertDialog.show({
//通過message設(shè)置告警信息
message:'當(dāng)前數(shù)據(jù)未保存,是否確認(rèn)離開?',
//通過alignment設(shè)置彈窗在界面垂直方向的對(duì)齊方式,此處設(shè)置為底部對(duì)齊
alignment:DialogAlignment.Bottom,
//通過offset設(shè)置基于對(duì)齊位置的便宜量
offset:{
dx:0,
dy:-20
},
//彈窗中左起第一個(gè)按鈕
primaryButton:{
value:'取消',
action:()=>{
console.info('Callbackcancelbuttonisclicked');
}
},
//彈窗中左起第二個(gè)按鈕
secondaryButton:{
value:'確定',
action:()=>{
//Exitingtheapp.
context.terminateSelf();
console.info('Callbackdefinitebuttonisclicked');
}
}
});
}
②使用 DatePickerDialog 實(shí)現(xiàn)日期滑動(dòng)選擇器彈窗

通過 start 和 end 分別設(shè)置日期區(qū)間的起始時(shí)間和末尾時(shí)間;通過 lunar 設(shè)置使用農(nóng)歷還是陽歷;使用 onAccept 監(jiān)聽選擇的日期,本例中通過變量 selectedDate 將選中的日期設(shè)置給參數(shù) selected,這樣彈窗彈出時(shí)的日期就默認(rèn)為上次選中的日期。

具體代碼如下:

datePickerDialog(dateCallback){
DatePickerDialog.show({
start:newDate('1900-1-1'),
end:newDate('2100-1-1'),
//通過變量selectedDate將選中的日期設(shè)置給參數(shù)selected
selected:this.selectedDate,
lunar:false,
//使用onAccept監(jiān)聽選擇的日期
onAccept:(value:DatePickerResult)=>{
letyear=value.year;
letmonth=value.month+1;
letday=value.day;
letbirthdate:string=this.getBirthDateValue(year,month,day);
//通過setFullYear將選中的日期傳遞給變量selectedDate
this.selectedDate.setFullYear(value.year,value.month,value.day)
//返回選中的日期
dateCallback(birthdate);
}
});
}
③使用 TextPickerDialog 實(shí)現(xiàn)文本滑動(dòng)選擇器彈窗

通過 range 設(shè)置文本選擇項(xiàng),使用 onAccept 監(jiān)聽選擇的文本項(xiàng),本例中通過變量 selectedGender 將選中的性別的索引設(shè)置給參數(shù) selected,這樣彈窗彈出時(shí)的性別就默認(rèn)為上次選中的性別。

具體代碼如下:

textPickerDialog(sexArray:Resource,sexCallback){
//判斷文本項(xiàng)的列表是否為空
if(this.isEmptyArr(sexArray)){
console.error('sexisnull');
return;
}
TextPickerDialog.show({
//通過range設(shè)置文本選擇項(xiàng)
range:sexArray,
//通過變量selectedGender將選中的性別的索引設(shè)置給參數(shù)selected
selected:this.selectedGender,
//使用onAccept監(jiān)聽選擇的文本項(xiàng)
onAccept:(result:TextPickerResult)=>{
sexCallback(result.value);
//獲取選中項(xiàng)的索引
this.selectedGender=result.index
},
onCancel:()=>{
console.info('TextPickerDialogonCancel');
}
});
}

④使用 CustomDialogController 實(shí)現(xiàn)自定義彈窗

當(dāng)現(xiàn)有彈窗不能滿足業(yè)務(wù)訴求時(shí),開發(fā)者可以自行設(shè)計(jì)彈窗的樣式。在實(shí)現(xiàn)自定義彈窗時(shí),需要將彈窗的 UI 放在被 @CustomDialog 修飾的自定義組件中,然后使用 CustomDialogController 的實(shí)例來控制彈窗的彈出和關(guān)閉。

具體代碼如下:

//使用@CustomDialog修飾自定義彈窗
@CustomDialog
structCustomDialogFrame{
...
//定義CustomDialogController
controller:CustomDialogController

build(){
Column(){
Text('興趣愛好').fontSize(20).margin({top:10,bottom:10})
TextInput({placeholder:'',text:this.textValue}).height(60).width('90%')
.onChange((value:string)=>{
this.textValue=value
})
Flex({justifyContent:FlexAlign.SpaceAround}){
Button('取消')
.onClick(()=>{
//點(diǎn)擊‘取消’,彈窗關(guān)閉
this.controller.close()
})
.backgroundColor('')
.fontColor('#007DFF')
Button('保存')
.onClick(()=>{
this.inputValue=this.textValue
//點(diǎn)擊‘保存’,彈窗關(guān)閉
this.controller.close()
})
.backgroundColor(0xffffff)
.fontColor('#007DFF')
}.margin({bottom:10})
}.justifyContent(FlexAlign.Start)
}
}
...
//實(shí)例化自定義彈窗
customDialogController:CustomDialogController=newCustomDialogController({
//使用上文創(chuàng)建的自定義彈窗進(jìn)行實(shí)例化
builder:CustomDialogFrame({
textValue:$textValue,
inputValue:$inputValue
}),
alignment:DialogAlignment.Bottom,
offset:{
dx:0,
dy:-20
}
});
...


完整代碼

本例完整代碼如下:

importContextfrom'@ohos.app.ability.common';
importhilogfrom'@ohos.hilog';

@Component
structTextFrame{
@Linkcontent:string;
privatetextImage:Resource;
privatetext:string;
onTextClick:()=>void;

build(){
Row(){
Image(this.textImage)
.width(24)
.height(24)
.margin({left:12})
Text(this.text)
.fontSize(16)
.margin({left:12})
.height(24)
Text(this.content)
.fontSize(16)
.textAlign(TextAlign.End)
.textOverflow({overflow:TextOverflow.Ellipsis})
.maxLines(1)
.margin({
left:16,
right:7
})
.layoutWeight(1)
.width('100%')
Image($r('app.media.ic_arrow'))
.width(12)
.height(24)
.margin({right:14})
}
.margin({top:24})
.borderRadius(24)
.backgroundColor(Color.White)
.width('93.3%')
.height(64)
.onClick(this.onTextClick)
}
}

@Component
structInputFrame{
privateinputImage:Resource;
privatehintText:string;

build(){
Row(){
Image(this.inputImage)
.width(24)
.height(24)
.margin({left:12})
TextInput({placeholder:this.hintText})
.fontSize(16)
.padding({left:12})
.placeholderColor('#99000000')
.backgroundColor(Color.White)
.fontWeight(FontWeight.Normal)
.fontStyle(FontStyle.Normal)
.fontColor(Color.Black)
.margin({right:32})
.layoutWeight(1)
.height(48)
}
.margin({top:24})
.borderRadius(24)
.backgroundColor(Color.White)
.width('93.3%')
.height(64)
}
}

@CustomDialog
structCustomDialogFrame{
@LinktextValue:string
@LinkinputValue:string
controller:CustomDialogController

build(){
Column(){
Text('興趣愛好').fontSize(20).margin({top:10,bottom:10})
TextInput({placeholder:'',text:this.textValue}).height(60).width('90%')
.onChange((value:string)=>{
this.textValue=value
})
Flex({justifyContent:FlexAlign.SpaceAround}){
Button('取消')
.onClick(()=>{
this.controller.close()
}).backgroundColor('').fontColor('#007DFF')
Button('保存')
.onClick(()=>{
this.inputValue=this.textValue
this.controller.close()
}).backgroundColor(0xffffff).fontColor('#007DFF')
}.margin({bottom:10})
}.justifyContent(FlexAlign.Start)
}
}

@Entry
@Component
structIndex{
@Statebirthdate:string='';
@Statesex:string='';
@StatetextValue:string='';
@StateinputValue:string='';
selectedDate:Date=newDate("2010-1-1")
selectedGender:number=0
privatesexArray:Resource=$r('app.strarray.sex_array');
customDialogController:CustomDialogController=newCustomDialogController({
builder:CustomDialogFrame({
textValue:$textValue,
inputValue:$inputValue
}),
alignment:DialogAlignment.Bottom,
offset:{
dx:0,
dy:-20
}
});

alertDialog(context:Context.UIAbilityContext){
AlertDialog.show({
message:'當(dāng)前數(shù)據(jù)未保存,是否確認(rèn)離開?',
alignment:DialogAlignment.Bottom,
offset:{
dx:0,
dy:-20
},
primaryButton:{
value:'取消',
action:()=>{
console.info('Callbackcancelbuttonisclicked');
}
},
secondaryButton:{
value:'確定',
action:()=>{
//Exitingtheapp.
context.terminateSelf();
console.info('Callbackdefinitebuttonisclicked');
}
}
});
}

datePickerDialog(dateCallback){
DatePickerDialog.show({
start:newDate('1900-1-1'),
end:newDate('2100-1-1'),
selected:this.selectedDate,
lunar:false,
onAccept:(value:DatePickerResult)=>{
letyear=value.year;
letmonth=value.month+1;
letday=value.day;
letbirthdate:string=this.getBirthDateValue(year,month,day);
this.selectedDate.setFullYear(value.year,value.month,value.day)
dateCallback(birthdate);
}
});
}

textPickerDialog(sexArray:Resource,sexCallback){
if(this.isEmptyArr(sexArray)){
console.error('sexisnull');
return;
}
TextPickerDialog.show({
range:sexArray,
selected:this.selectedGender,
onAccept:(result:TextPickerResult)=>{
sexCallback(result.value);
this.selectedGender=result.index
},
onCancel:()=>{
console.info('TextPickerDialogonCancel');
}
});
}

getBirthDateValue(year:number,month:number,day:number):string{
letbirthdate:string=`${year}${'年'}${month}`+
`${'月'}${day}${'日'}`;
returnbirthdate;
}

isEmpty(obj):boolean{
returnobj===undefined||obj===null||obj==='';
}

isEmptyArr(array):boolean{
returnthis.isEmpty(array)||array.length===0;
}

build(){
Row(){
Column(){
Row(){
Image($r('app.media.ic_back'))
.width(26)
.height(26)
.alignSelf(ItemAlign.Start)
.margin({
left:'7.2%',
top:19
})
.onClick(()=>{
letcontext=getContext(this)asContext.UIAbilityContext;
this.alertDialog(context);
})
Text('個(gè)人信息')
.fontColor(Color.Black)
.fontSize(20)
.margin({top:20,left:20})
.alignSelf(ItemAlign.Center)
}.width('100%')
Image($r('app.media.ic_avatar'))
.width(56)
.height(56)
.alignSelf(ItemAlign.Center)
.margin({top:'5.5%'})
Text('頭像')
.fontColor(Color.Black)
.fontSize(16)
.margin({top:'2.1%'})
.alignSelf(ItemAlign.Center)
InputFrame({
inputImage:$r('app.media.ic_nickname'),
hintText:'昵稱'
})
TextFrame({
textImage:$r('app.media.ic_birthdate'),
text:'出生日期',
content:$birthdate,
onTextClick:()=>{
this.datePickerDialog((birthValue:string)=>{
this.birthdate=birthValue;
});
}
})
TextFrame({
textImage:$r('app.media.ic_sex'),
text:'性別',
content:$sex,
onTextClick:()=>{
this.textPickerDialog(this.sexArray,(sexValue:string)=>{
this.sex=sexValue;
});
}
})
InputFrame({
inputImage:$r('app.media.ic_signature'),
hintText:'個(gè)性簽名'
})
TextFrame({
textImage:$r('app.media.ic_hobbies'),
text:'興趣愛好',
content:$textValue,
onTextClick:()=>{
this.customDialogController.open();
}
})
}
.backgroundColor('#F5F5F5')
.height('100%')
.width('100%')
}
.height('100%')
}
}



審核編輯:劉清

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

    關(guān)注

    31

    文章

    3920

    瀏覽量

    20678

原文標(biāo)題:OpenHarmony上使用彈窗

文章出處:【微信號(hào):gh_834c4b3d87fe,微信公眾號(hào):OpenHarmony技術(shù)社區(qū)】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。

收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評(píng)論

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

    env中打不開menuconfig的配置界面,不出現(xiàn)彈窗是怎么回事?

    env中打不開menuconfig的配置界面,不出現(xiàn)彈窗
    發(fā)表于 09-23 06:01

    安裝了platformIO插件,重啟過軟件,通用項(xiàng)目中點(diǎn)擊 基于platformIO,就彈窗說沒安裝,怎么解決?

    安裝了platformIO插件,重啟過軟件,通用項(xiàng)目中點(diǎn)擊 基于platformIO,就彈窗說沒安裝。rtthreadstudio版本是最新的。 請(qǐng)問問題出在哪里?如何解決呢?
    發(fā)表于 09-01 06:52

    樹莓派Pico運(yùn)用不同的并行化手段

    樹莓派Pico由RP2040微控制器驅(qū)動(dòng),其搭載兩個(gè)CPU核,這讓它非常適合探索并行計(jì)算。本文通過真實(shí)的數(shù)字信號(hào)處理樣例來說明從雙核架構(gòu)中提取最大價(jià)值的方法和考量。
    的頭像 發(fā)表于 08-29 09:51 ?3506次閱讀
    <b class='flag-5'>在</b>樹莓派Pico<b class='flag-5'>上</b>運(yùn)<b class='flag-5'>用不</b>同的并行化手段

    分享---超聲波焊接機(jī)設(shè)備實(shí)現(xiàn)告 \"警彈窗\" 效果的簡單方法

    實(shí)際設(shè)計(jì)產(chǎn)品UI界面中,經(jīng)常碰到要設(shè)計(jì)”告警彈窗”功能如,設(shè)備運(yùn)行中產(chǎn)生了告警信息時(shí),要彈出窗口提示用戶做操作。 使用拓普微廠家的串口屏開發(fā)工具SGTools,可以很容易的實(shí)現(xiàn)”告警彈窗”功能,只需要簡單設(shè)置屬性就可以實(shí)現(xiàn);
    發(fā)表于 08-21 11:17

    鴻蒙非侵入式彈窗新解法,企查查正式開源“QuickDialog”彈窗組件庫

    近日,企查查將其自研的鴻蒙彈窗組件庫“QuickDialog”開源,并上線至?OpenHarmony 三方庫中心倉。這是鴻蒙生態(tài)首個(gè)支持“彈窗堆棧暫存能力”的非侵入式彈窗解決方案,憑借
    的頭像 發(fā)表于 07-31 10:40 ?505次閱讀
    鴻蒙非侵入式<b class='flag-5'>彈窗</b>新解法,企查查正式開源“QuickDialog”<b class='flag-5'>彈窗</b>組件庫

    《仿盒馬》app開發(fā)技術(shù)分享-- 分類模塊頂部導(dǎo)航列表彈窗(16)

    技術(shù)棧 Appgallery connect 開發(fā)準(zhǔn)備 一節(jié)我們實(shí)現(xiàn)了分類頁面的頂部導(dǎo)航欄列表,并且實(shí)現(xiàn)了首頁金剛區(qū)跟首頁導(dǎo)航欄的聯(lián)動(dòng),這一節(jié)我們實(shí)現(xiàn)導(dǎo)航欄列表的彈窗功能,需要學(xué)習(xí)的知識(shí)點(diǎn)有自定義
    發(fā)表于 06-30 10:34

    《仿盒馬》app開發(fā)技術(shù)分享-- 商品規(guī)格彈窗(11)

    技術(shù)棧 Appgallery connect 開發(fā)準(zhǔn)備 一節(jié)我們實(shí)現(xiàn)了商品詳情頁面,并且成功頁面上展示了商品的圖片、商品規(guī)格、活動(dòng)詳情等信息,要知道同一種商品大多數(shù)都是有多種型號(hào)跟規(guī)格的,所以
    發(fā)表于 06-30 09:15

    HarmonyOS實(shí)戰(zhàn):首頁多彈窗順序彈出終極解決方案

    背景 隨著應(yīng)用軟件功能的不斷增加,應(yīng)用程序軟件首頁成為彈窗的重災(zāi)區(qū),不僅有升級(jí)彈窗,還有積分彈窗,簽到,引導(dǎo)等各種彈窗。為了徹底解彈窗問題,
    的頭像 發(fā)表于 06-09 16:47 ?600次閱讀
    HarmonyOS實(shí)戰(zhàn):首頁多<b class='flag-5'>彈窗</b>順序彈出終極解決方案

    如何在KaihongOS操作系統(tǒng)寫一個(gè)彈窗組件

    寫一個(gè)彈窗組件 KaihongOS框架提供了彈窗的API接口,開發(fā)者可直接使用,詳情請(qǐng)參考@ohos.promptAction (彈窗)。但在開發(fā)過程中當(dāng)提供的彈窗接口無法滿足需求時(shí)
    發(fā)表于 04-30 06:44

    請(qǐng)問下,openharmony支持哪一款龍芯的開發(fā)板?有沒有開源的龍芯的openharmony源碼?

    想買個(gè)2k0300的開發(fā)板學(xué)習(xí)龍芯和openharmony,愣是沒有看到提供openharmony源碼的,也沒與看到開源的代碼。giteeopenharmony的龍芯sig倉庫也是
    發(fā)表于 04-26 13:06

    DialogHub上線OpenHarmony開源社區(qū),高效開發(fā)鴻蒙應(yīng)用彈窗

    作為鴻蒙應(yīng)用開發(fā)者,使用ArkUI現(xiàn)有能力進(jìn)行彈窗開發(fā)時(shí),總會(huì)遇到一些讓人糾結(jié)的交互問題:應(yīng)用內(nèi)進(jìn)行消息提示時(shí),既要求消息內(nèi)容支持圖文混排,又要求彈窗本身不能打斷用戶交互(頁面滑動(dòng)、頁面
    發(fā)表于 04-03 17:30

    STM32H5使用fatfs寫函數(shù)時(shí)用不了DMA的寫方式,應(yīng)該怎么使用呢?

    請(qǐng)問STM32H5使用fatfs寫函數(shù)時(shí),用不了DMA的寫方式,應(yīng)該怎么使用呢,有人遇到過類似的問題嘛
    發(fā)表于 03-12 07:10

    OpenHarmony應(yīng)用與游戲開發(fā)領(lǐng)域的前沿成果

    日前,由開放原子開源基金會(huì)主辦的第二屆OpenHarmony創(chuàng)新應(yīng)用挑戰(zhàn)賽決賽路演北京圓滿結(jié)束,作為第二屆開放原子大賽的重要賽項(xiàng)之一,本屆賽事匯聚全球418支團(tuán)隊(duì),產(chǎn)出超過110個(gè)創(chuàng)新作品,集中
    的頭像 發(fā)表于 03-03 15:04 ?875次閱讀

    蜂鳥板Openharmony系統(tǒng)跑QT程序

    將QT程序放到Openharmony系統(tǒng)跑,可以運(yùn)行,但是會(huì)被覆蓋掉。(用的網(wǎng)盤里面的install,支持QT組件的版本)。 運(yùn)行情況是,終端運(yùn)行QT程序,可以正常運(yùn)行出來,但是觸摸屏幕后,會(huì)被
    發(fā)表于 02-26 13:04

    鴻蒙原生開源庫ViewPoolOpenHarmony社區(qū)正式上線

    近日,由伙伴參與共建的鴻蒙原生開源庫“ViewPool”OpenHarmony社區(qū)正式上線。這個(gè)開發(fā)庫是基于OpenHarmony技術(shù)孵化的成果,充分發(fā)揮了平臺(tái)的技術(shù)特性,同時(shí)融入了伙伴
    的頭像 發(fā)表于 12-20 14:44 ?835次閱讀