可以通过全局的焦点控制对象FocusController的clearFocus()方法收起软键盘,示例代码如下:
@Entry
@Component
struct ClickBlankHideKeyboard {
build() {
Column({ space: 12 }) {
TextInput({ placeholder: 'Please enter your account' })
.height(40)
TextInput({ placeholder: 'Please input a password' })
.height(40)
Button('log on').width('100%')
.onClick(() => {
this.getUIContext().getFocusController().clearFocus();
})
}
}
} 参考链接: