HarmonyOS 弹窗不避让软键盘

HarmonyOS 弹窗不避让软键盘。

HarmonyOS
2024-08-30 15:57:57
990浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

参考:

import {Test1} from './Test1' 
@CustomDialog 
export struct CustomDialogExample { 
  controller: CustomDialogController 
  @Consume ('pageInfos') pageInfos: NavPathStack 
  build() { 
    Column() { 
      Text('跳转') 
        .onClick(() => { 
          this.pageInfos.pushPath({ name: 'pageOne' }) //将name指定的NavDestination页面信息入栈 
        }) 
    }.height(200).width(300).backgroundColor(Color.White) 
  } 
} 
// Test1.ets 
import promptAction from '@ohos.promptAction'; 
// @Entry 
@Component 
export struct Test1 { 
  @State message: string = 'Hello World'; 
  build() { 
    NavDestination(){ 
      Row() { 
        Column() { 
          Text(this.message) 
            .fontSize(50) 
            .fontWeight(FontWeight.Bold) 
        } 
        .width('100%') 
      } 
      .height('100%') 
    }.onBackPressed(()=>{ 
      promptAction.showToast({message:'123'}) 
      return false 
    }) 
  } 
} 
// Index.ets 
import {Test1} from "./Test1" 
@Entry 
@Component 
struct CustomdialogJump { 
  aboutToAppear(){ 
    // this.dialogController.open() 
  } 
  @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack() 
  @State textValue: string = '输入' 
  // 显隐控制设置为不占用 
  @State visible: Visibility = Visibility.None 
  @Builder 
  PageMap(name: string) { 
    if (name === 'pageOne') { 
      Test1() 
    } 
  } 
  build() { 
    Navigation(this.pageInfos){ 
      Stack() { 
        Row() { 
          // 初始页面 
          Column() { 
            Text('我是第一个页面') 
              .fontSize(30) 
              .fontWeight(FontWeight.Bold) 
            // 触发dialog的地方 
            Button('按钮') 
              .onClick(() => { 
                console.log("hit me!") 
                if (this.visible == Visibility.Visible) { 
                  this.visible = Visibility.None 
                } else { 
                  this.visible = Visibility.Visible 
                } 
              }) 
              .backgroundColor(0x777474) 
              .fontColor(0x000000) 
          } 
          .height('100%') 
          .width('100%') 
          .justifyContent(FlexAlign.Start) 
          .alignItems(HorizontalAlign.Center) 
        } 
        .height('100%') 
        .backgroundColor('#FFF') 
        //这里开始是构造弹窗效果主要需要修改的地方,首先是加了一个半透明灰色的蒙层效果 
        Text('') 
          .onClick(() => { 
            if (this.visible == Visibility.Visible) { 
              this.visible = Visibility.None 
            } else { 
              this.visible = Visibility.Visible 
            } 
          }) 
          .width('100%') 
          .height('100%') 
            // 透明度可以自己调节一下 
          .opacity(0.5) 
          .backgroundColor(Color.Black) 
          .visibility(this.visible) 
        Column() { 
          // 这个可以调节对话框效果,栅格布局,xs,sm,md,lg分别为四种规格 
          // 下面的breakpoints是用来区别当前属于哪个类型的断点 
          // gridRow里的栅格数量为总数,gridCol里的就是偏移和假Dialog所占据的栅格数 
          GridRow({ 
            columns:{xs:1 ,sm: 4, md: 8, lg: 12}, 
            breakpoints: { value: ["400vp", "600vp", "800vp"], 
              reference: BreakpointsReference.WindowSize }, 
          }) 
          { 
            GridCol({ 
              span:{xs:1 ,sm: 2, md: 4, lg: 8}, 
              offset:{xs:0 ,sm: 1, md: 2, lg: 2} 
            }){ 
              // 这里放的就是原Dialog里的column里的东西,稍微改改应该就可以用了 
              Column() { 
                Text('安全隐私').fontSize(20).margin({ top: 10, bottom: 10 }) 
                Text('是否跳转到隐私详情页面?').fontSize(16).margin({ bottom: 10 }) 
                Search() 
                  .backgroundColor(Color.Gray) 
                  .height(200) 
                Flex({ justifyContent: FlexAlign.SpaceAround }) { 
                  Button('取消') 
                    .onClick(() => { 
                      if (this.visible == Visibility.Visible) { 
                        this.visible = Visibility.None 
                      } else { 
                        this.visible = Visibility.Visible 
                      } 
                    }).backgroundColor(0xffffff).fontColor(Color.Black) 
                  Button('确定') 
                    .onClick(() => { 
                      this.pageInfos.pushPath({ name: 'pageOne' }) 
                    }).backgroundColor(0xffffff).fontColor(Color.Red) 
                }.margin({ bottom: 10 }) 
              } 
              .backgroundColor(0xffffff) 
              .visibility(this.visible) 
              .clip(true) 
              .borderRadius(20) 
            } 
          } 
        }.width('100%')//设置弹窗宽度 
      }.height('100%') 
    }.navDestination(this.PageMap) 
    .hideTitleBar(true) 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
分享
微博
QQ
微信
回复
2024-08-30 19:58:35
相关问题
如何实现弹窗软键盘避让
2352浏览 • 1回复 待解决
HarmonyOS 弹窗布局被软键盘压缩
613浏览 • 1回复 待解决
HarmonyOS 如何实现弹窗不规避软键盘
1011浏览 • 1回复 待解决
HarmonyOS 软键盘操作API
554浏览 • 1回复 待解决
HarmonyOS 如何监听软键盘弹出
918浏览 • 1回复 待解决
HarmonyOS 如何监听软键盘收起
965浏览 • 1回复 待解决
HarmonyOS 软键盘弹出方式
898浏览 • 1回复 待解决
HarmonyOS 软键盘问题
506浏览 • 1回复 待解决
HarmonyOS dialog和软键盘
713浏览 • 1回复 待解决
HarmonyOS TextInput软键盘监听
869浏览 • 1回复 待解决
如何判断软键盘是否弹出
2833浏览 • 1回复 待解决
关于软键盘弹出遮挡问题
1923浏览 • 1回复 待解决
如何主动收起软键盘
966浏览 • 1回复 待解决
HarmonyOS 软键盘弹出控制与检测
805浏览 • 1回复 待解决
HarmonyOS 如何代码控制软键盘弹出?
1179浏览 • 1回复 待解决
HarmonyOS 如何控制软键盘打开、收起?
2013浏览 • 1回复 待解决
HarmonyOS 软键盘挤压Toast弹框
569浏览 • 1回复 待解决