可以通过让TextInput失焦的方法,让软键盘收起,目前让TextInput失焦的方法只能通过让别的组件获焦而使当前组件失焦,可以将焦点转移给其他组件, 例如,提供一个button组件,并设置点击时可获焦,当点击按钮时,可让TextInput失焦,软键盘收起使用focusContrl.requestFocus接口使指定组件获取焦点。可参考文档https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-textinput-0000001815086902-V5\#ZH-CN\_TOPIC\_0000001815086902\_\_enablekeyboardonfocus10https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-focus-V5\#focuscontrol9示例如下:import inputMethod from '@ohos.inputMethod'; @Entry @Component struct Index2 { @State message: string = 'Hello World'; build() { Row() { Column() { TextInput() .backgroundColor(Color.Pink) Button('拉起软键盘').onClick(()=>{ inputMethod.getController().showTextInput() }) .backgroundColor(Color.Green) Button('隐藏软键盘').onClick(()=>{ inputMethod.getController().hideTextInput() }) .backgroundColor(Color.Orange) } .width('100%') .height('100%') } .height('100%') } }
可以通过让TextInput失焦的方法,让软键盘收起,目前让TextInput失焦的方法只能通过让别的组件获焦而使当前组件失焦,可以将焦点转移给其他组件, 例如,提供一个button组件,并设置点击时可获焦,当点击按钮时,可让TextInput失焦,软键盘收起使用focusContrl.requestFocus接口使指定组件获取焦点。
可参考文档
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-textinput-0000001815086902-V5\#ZH-CN\_TOPIC\_0000001815086902\_\_enablekeyboardonfocus10
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-focus-V5\#focuscontrol9
示例如下: