在HarmonyOS NEXT 中主动隐藏输入弹框的方法?

阅读 658
1 个回答

你可以给外层容器添加个点击事件,在点击事件中调用controller.stopEditing()方法移除输入框焦点即可隐藏键盘。

@Entry 
@Component 
struct TextInputExample { 
  controller: TextInputController = new TextInputController(); 
 
  build() { 
    Column() { 
      TextInput({ controller: this.controller }) } 
    .width('100%') .height('100%') 
    .onClick(()=>{ this.controller.stopEditing(); 
    }) 
  } 
}