在HarmonyOS NEXT开发中TextArea与系统键盘的使用方式?

在HarmonyOS NEXT开发中TextArea与系统键盘的使用方式?

阅读 949
1 个回答

你可以通过设置焦点来控制
API链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-refere...
参考代码:

@Entry 
@Component 
struct Page { 
  @State hideState: boolean = true 
  controller: TextAreaController = new TextAreaController() 
  foucsC = this.getUIContext().getFocusController() 
  selectIndex = 0 
 
  build() { 
    Column() { 
      Column() { 
        Text('隐藏/显示面板') 
          .onClick(() => { 
            this.hideState = !this.hideState 
            this.foucsC.clearFocus() 
            this.foucsC.requestFocus('TextInput') 
          }) 
      }.layoutWeight(1) 
      .width('100%') 
      .justifyContent(FlexAlign.Center) 
      .backgroundColor(Color.Green) 
 
      Column() { 
        TextArea({ controller: this.controller }) 
          .id('TextInput') 
        Column() { 
          Text('菜单面板') 
        } 
        .width('100%') 
        .height(300) 
        .justifyContent(FlexAlign.Center) 
        .backgroundColor(Color.Blue) 
        .visibility(this.hideState ? Visibility.None : Visibility.Visible) 
      } 
 
    }.width('100%') 
    .height('100%') 
  } 
}