HarmonyOS 弹窗跟软键盘间的间如何去除

HarmonyOS 弹窗跟软键盘间的间如何去除

HarmonyOS
2024-08-08 19:08:49
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
FengTianYa
1
import window from '@ohos.window' 
import { data } from '@kit.TelephonyKit' 
 
@Entry 
@Component 
export struct LightPublishMine { 
  private window?: window.Window 
  @State keyboardHeightVp: number = 0 
  @State navHeight: number = 0 
  @State safeAreaTop: number = 0 
 
  aboutToAppear() { 
 
    window.getLastWindow(getContext(this)).then((win) => { 
      this.window = win 
      if (this.window) { 
        this.navHeight = px2vp(this.window.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR)// 导航条高度 
          .bottomRect 
          .height) 
        this.safeAreaTop = px2vp(this.window.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height) 
 
        this.window.on('keyboardHeightChange', (data) => { 
          console.info('Succeeded in enabling the listener for keyboard height changes. 键盘 Data: ' + data); 
          this.keyboardHeightVp = px2vp(data) 
          console.info('Succeeded in enabling the listener for keyboard height changes. Data: ' + (this.keyboardHeightVp - this.navHeight)); 
          console.info('Succeeded in enabling the listener for keyboard height changes. 导航条Data: ' + this.navHeight); 
        }); 
      } 
    }) 
  } 
 
  aboutToDisappear() { 
    if (this.window) { 
      this.window.off('keyboardHeightChange') 
      this.window = undefined 
    } 
    this.keyboardHeightVp = 0 
  } 
 
  build() { 
    Row() { 
      Column() { 
        TextInput() 
          .backgroundColor(Color.White) 
        Blank().backgroundColor(Color.Red).height(this.keyboardHeightVp - this.navHeight).width('100%') 
      } 
      .width('100%') 
    } 
    .height('100%') 
    .backgroundColor(Color.Green) 
    .alignItems(VerticalAlign.Bottom) 
    .expandSafeArea([SafeAreaType.KEYBOARD], [SafeAreaEdge.BOTTOM]) 
  } 
} 
 
@Entry 
@Component 
struct BindSheetExample { 
  @State isShow: boolean = false 
  @State isShow2: boolean = false 
  @State sheetHeight: number = 300; 
  @State showDragBar: boolean = true; 
 
  @Builder 
  myBuilder(text: string) { 
    Column() { 
      Text('Custom dialog Message').fontSize(10) 
      TextInput({ text: text, placeholder: 'input your word...' }) 
        .placeholderColor(Color.Grey) 
        .placeholderFont({ size: 14, weight: 400 }) 
        .caretColor(Color.Blue) 
        .width('95%') 
        .height(40) 
        .margin(20) 
        .fontSize(14) 
        .fontColor(Color.Black) 
        .inputFilter('[a-z]', (e) => { 
          console.log(JSON.stringify(e)) 
        }) 
        .onChange((value: string) => { 
          text = value 
        }) 
    } 
  } 
 
  build() { 
    Column() { 
      Button("transition modal 1") 
        .onClick(() => { 
          this.isShow = true 
        }) 
        .fontSize(20) 
        .margin(10) 
        .bindSheet($$this.isShow, this.myBuilder(''), 
          { 
            height: this.sheetHeight, 
            detents: [SheetSize.FIT_CONTENT, SheetSize.MEDIUM, SheetSize.LARGE], 
            dragBar: this.showDragBar, 
            backgroundColor: Color.Gray, 
            onAppear: () => { 
              console.log("BindSheet onAppear.") 
            }, 
            onDisappear: () => { 
              console.log("BindSheet onDisappear.") 
            } 
          }) 
    } 
    .justifyContent(FlexAlign.Center) 
    .width('100%') 
    .height('100%') 
  } 
}
分享
微博
QQ
微信
回复
2024-08-08 21:29:02
相关问题
HarmonyOS 弹窗不避让软键盘
399浏览 • 1回复 待解决
如何实现弹窗软键盘避让
1388浏览 • 1回复 待解决
HarmonyOS 如何代码控制软键盘弹出?
353浏览 • 1回复 待解决
如何判断软键盘是否弹出
2028浏览 • 1回复 待解决
HarmonyOS 如何获取软键盘高度?
423浏览 • 1回复 待解决
HarmonyOS如何代码收起软键盘
420浏览 • 1回复 待解决
如何主动收起软键盘
256浏览 • 1回复 待解决
HarmonyOS如何获取系统软键盘高度?
351浏览 • 1回复 待解决
关于软键盘弹出遮挡问题
1100浏览 • 1回复 待解决
HarmonyOS 关于软键盘相关问题
348浏览 • 0回复 待解决
CustomDialog与软键盘问题
331浏览 • 1回复 待解决
API8 怎么隐藏软键盘
2471浏览 • 1回复 待解决
软键盘弹出时,页面的自适应
1406浏览 • 1回复 待解决