非输入框区域收起软键盘使用stopInputSession结束输入会话.onTouch(() => { // 收起键盘 let inputMethodController = inputMethod.getController(); inputMethodController.stopInputSession() })参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-inputmethod-V5\#stopinputsession9通过让TextInput失焦的方法,让软键盘收起,目前让TextInput失焦的方法只能通过让别的组件获焦而使当前组件失焦,可以将焦点转移给其他组件。例如,提供一个button组件,并设置点击时可获焦,当点击按钮时,可让TextInput失焦,软键盘收起参考demo:@Entry @Component struct TextInputExample { @State oneButtonColor: string = '#FFC0CB' build() { Column() { TextInput({ placeholder: '' }) .width('95%') .height(40) .margin(20) .onFocus(() => { console.log("input获焦"); }) .onBlur(() => { console.log("input失焦"); }) // button设置点击时能获焦 Button('First Button') .backgroundColor(this.oneButtonColor) .width(260) .height(70) .fontColor(Color.Black) .focusable(true) // 设置点击获取焦点 .focusOnTouch(true) .onFocus(() => { this.oneButtonColor = '#FF0000' }) .onBlur(() => { this.oneButtonColor = '#FFC0CB' }) }.width('100%') } }
非输入框区域收起软键盘使用stopInputSession结束输入会话
参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-inputmethod-V5\#stopinputsession9
通过让TextInput失焦的方法,让软键盘收起,目前让TextInput失焦的方法只能通过让别的组件获焦而使当前组件失焦,可以将焦点转移给其他组件
。例如,提供一个button组件,并设置点击时可获焦,当点击按钮时,可让TextInput失焦,软键盘收起
参考demo: