<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      鴻蒙(HarmonyOS)常見的三種彈窗方式

      最近有一個想法,做一個針對鴻蒙官方API的工具箱項目,介紹常用的控件,以及在項目中如何使用,今天介紹Harmony中如何實現(xiàn)彈窗功能。

      警告彈窗

      警告彈窗是一個App中非常常用的彈窗,例如:

      • 刪除一條記錄,提示一下用戶:您確定要刪除嗎?
      • 在App首頁,點擊返回時,提示一下用戶:您確定要退出App嗎?

      使用AlertDialog.show方法進行彈窗,這個方法支持傳入以下三個類中的任意一個對象

      • AlertDialogParamWithConfirm
      • AlertDialogParamWithButtons
      • AlertDialogParamWithOptions

      以AlertDialogParamWithButtons對象進行說明,下面表格介紹常用屬性:

      參數(shù)名 參數(shù)類型 必填 參數(shù)描述
      title ResourceStr 彈窗標(biāo)題
      message ResourceStr 彈窗內(nèi)容
      autoCancel boolean 點擊遮障層時,是否關(guān)閉彈窗。默認(rèn)值:true
      primaryButton 按鈕的文本內(nèi)容、文本色、按鈕背景色和點擊回調(diào)
      secondaryButton 按鈕的文本內(nèi)容、文本色、按鈕背景色和點擊回調(diào)
      cancel () => void 點擊遮障層關(guān)閉dialog時的回調(diào)
      alignment DialogAlignment 彈窗在豎直方向上的對齊方式。默認(rèn)值:DialogAlignment.Default

      接下來,我們用代碼來實現(xiàn)一下:

      AlertDialog.show({
          title:"彈窗標(biāo)題",
          message:"這是彈窗內(nèi)容",
          autoCancel:true,//點擊遮障層時,是否關(guān)閉彈窗。默認(rèn)值:true
          alignment: DialogAlignment.Center,//彈窗在豎直方向上的對齊方式。默認(rèn)值:DialogAlignment.Default
          primaryButton: {
              value: "取消",
              fontColor: '#181818',
              action: () => {
                  AppUtil.showToast("點擊了取消按鈕");
              }
          },
          secondaryButton: {
              value: "確定",
              fontColor: $r('app.color.mainColor'),
              action: () => {
                  AppUtil.showToast("點擊了確定按鈕");
              }
          },
          cornerRadius:12,//彈窗邊框弧度
          width:'80%', //彈窗寬度
          cancel:()=>{
              AppUtil.showToast("點擊遮障層關(guān)閉dialog時的回調(diào)");
          }
      })
      

      效果圖:

      參考官方鏈接:

      https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V2/ts-methods-alert-dialog-box-0000001478341185-V2

      自定義彈窗

      自定義彈窗相比警告彈窗更為靈活,支持自定義彈窗的樣式與內(nèi)容。

      自定義彈窗的參數(shù):
      參數(shù)名 參數(shù)類型 必填 參數(shù)描述
      builder CustomDialog 自定義彈窗內(nèi)容構(gòu)造器。
      cancel () => void 點擊遮障層退出時的回調(diào)。
      autoCancel boolean 是否允許點擊遮障層退出。默認(rèn)值:true
      alignment DialogAlignment 彈窗在豎直方向上的對齊方式。默認(rèn)值:DialogAlignment.Default
      offset Offset 彈窗相對alignment所在位置的偏移量。
      customStyle boolean 彈窗容器樣式是否自定義。默認(rèn)值:false,彈窗容器的寬度根據(jù)柵格系統(tǒng)自適應(yīng),不跟隨子節(jié)點;高度自適應(yīng)子節(jié)點,最大為窗口高度的90%;圓角為24vp。
      gridCount8+ number 彈窗寬度占柵格寬度的個數(shù)。默認(rèn)為按照窗口大小自適應(yīng),異常值按默認(rèn)值處理,最大柵格數(shù)為系統(tǒng)最大柵格數(shù)。

      代碼實現(xiàn)

      我們使用自定義彈窗實現(xiàn)隱私政策彈窗,新建PrivacyPolicyDialogBackUp類,也就是內(nèi)容構(gòu)造器,使用@CustomDialog修飾,內(nèi)部有一個屬性controller: CustomDialogController,這些都是常規(guī)寫法,然后在build中實現(xiàn)界面布局。

      @CustomDialog
      export default struct PrivacyPolicyDialogBackUp{
          controller: CustomDialogController
      
          cancel!: () => void
          confirm!: () => void
      
          build() {
              Column() {
                  Text($r('app.string.simple_user_policy')).fontSize(18).fontColor($r('app.color.title_color')).margin({ top: 30, bottom: 19 })
      
                  Scroll(){
                      Text(){
                          Span($r('app.string.privacy_policy_start'))
                          Span($r('app.string.user_agreement_two')).fontColor($r('app.color.mainColor')).onClick(() => {
                              this.openWebUrl("/useragreement.html");
                          })
                          Span($r('app.string.and'))
                          Span($r('app.string.privacy_policy_two')).fontColor($r('app.color.mainColor')).onClick(() => {
                              this.openWebUrl("/privacypolicy.html");
                          })
                          Span($r('app.string.simple_privacy_policy'))
                      }.fontSize(16).fontColor($r('app.color.body_color')).margin({
                          left:25,
                          right:25
                      })
                  }.height(120)
      
                  Column(){
                      Button($r('app.string.disagree_privacy_policy')).onClick(() => {
                          this.controller.close();
                          this.cancel();
                      }).fontColor($r('app.color.other_color')).fontSize(15).backgroundColor(Color.Transparent)
      
                      Button($r('app.string.agree_privacy_policy')).onClick(() => {
                          this.controller.close();
                          this.confirm();
                      }).fontColor($r('app.color.white')).fontSize(17)
                          .linearGradient({
                              direction: GradientDirection.Right, colors:[[$r('app.color.start_main_color'),0.0],[$r('app.color.end_main_color'),1.0]]
                          }).width('80%').margin({
                          top:15,bottom:21
                      }).borderRadius(24)
                  }
              }
          }
      
          openWebUrl(urlSuffix:string){
              let url= AppConstant.URL+urlSuffix;
              logger.info("url:"+url)
              router.pushUrl({
                  url: Pages.WebViewPage,
                  params:{
                      data1: 'message',
                      url: url,  // 傳遞的 URL 參數(shù)
                  }
              }, router.RouterMode.Single)
          }
      }
      

      在組件中創(chuàng)建CustomDialogController實例,指定builder屬性,就是上面寫的內(nèi)容構(gòu)造器

      privacyPolicyDialog: CustomDialogController = new CustomDialogController({
        builder: PrivacyPolicyDialog({
          cancel:this.onCancel.bind(this),
          confirm:this.onAgree.bind(this)
        }),
        alignment: DialogAlignment.Default,  // 可設(shè)置dialog的對齊方式,設(shè)定顯示在底部或中間等,默認(rèn)為底部顯示
        cornerRadius:13,
        autoCancel:false
      })
      

      顯示彈窗

      this.privacyPolicyDialog.open();
      

      關(guān)閉彈窗

      this.privacyPolicyDialog.close();
      

      效果圖:

      參考官方鏈接:

      https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V2/ts-methods-custom-dialog-box-0000001477981237-V2

      加載中彈窗

      加載中彈窗彈窗其實就是自定義彈窗實現(xiàn),只是內(nèi)容構(gòu)造器不一樣而已,給Image組件設(shè)置animation動畫,無限循環(huán)圖片

      @CustomDialog
      export default struct LoadingDialog {
          controller: CustomDialogController
      
          private loadingText: string|Resource = "加載中..."
          @State angle:number = 10
      
          aboutToAppear(){
              setTimeout(()=>{
                  this.angle = 1440 // 設(shè)定一個大的旋轉(zhuǎn)角度,確保動畫執(zhí)行
              },100)
          }
      
          build() {
              Column(){
                  Image($r('app.media.icon_loading_3'))
                      .width(70)
                      .height(70)
                      .rotate({angle:this.angle})
                      .animation({
                          duration: 5000,
                          curve: Curve.Linear,
                          delay: 0,
                          iterations: -1, // 設(shè)置-1表示動畫無限循環(huán)
                          playMode: PlayMode.Normal
                      })
      
      
                  Text(this.loadingText).fontSize(14).fontColor(0xffffff).margin({top:10})
              }.backgroundColor(0x88000000).borderRadius(10).padding({
                  left:20,right:20,top:10,bottom:10
              })
          }
      }
      

      效果圖:

      源碼下載:

      https://github.com/ansen666/harmony_tools

      如果您想第一時間看我的后期文章,掃碼關(guān)注公眾號

            安輝編程筆記 - 開發(fā)技術(shù)分享
                   掃描二維碼加關(guān)注
      

      安輝編程筆記

      posted @ 2024-08-31 09:17  安輝  閱讀(1587)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 桃源县| 亚洲真人无码永久在线| 本溪| 亚洲av午夜福利精品一区二区| 久久精品伊人波多野结衣| 中文字幕国产精品综合| 成人欧美一区二区三区在线观看| 欲乱人妻少妇邻居毛片| 秋霞AV鲁丝片一区二区| av中文字幕一区人妻| 北岛玲中文字幕人妻系列| 最新精品国偷自产在线| 欧美成人精品在线| 玖玖在线精品免费视频| 绍兴县| 亚洲国产日韩a在线播放| 亚洲av永久无码天堂影院| 国产视频一区二区三区麻豆| 性XXXX视频播放免费直播| 亚洲精品岛国片在线观看| 日韩精品无码区免费专区| 四虎精品视频永久免费| 国产91久久精品一区二区| 91福利一区福利二区| 亚洲综合在线一区二区三区| 亚洲日韩AV秘 无码一区二区| 色8久久人人97超碰香蕉987| 人妻中文字幕一区二区视频| 亚洲国产另类久久久精品小说| 日本一区二区中文字幕久久| 国产白嫩护士在线播放| 亚洲成人av在线资源| 亚洲色在线v中文字幕| 亚洲日韩AV秘 无码一区二区| 我要看亚洲黄色太黄一级黄| 国产永久免费高清在线| 扒开双腿猛进入喷水高潮叫声| 国产精品永久免费无遮挡| 亚洲少妇人妻无码视频| 人妻少妇88久久中文字幕| 中文字幕无码av不卡一区|