TextInput输入框如何失去焦点?输入框获取焦点后,点击页面上其他任意地方无法失去焦点,焦点一直在输入框中?

如题:TextInput输入框如何失去焦点?输入框获取焦点后,点击页面上其他任意地方无法失去焦点,焦点一直在输入框中?

阅读 330
1 个回答

可以通过stopediting退出软件盘的编辑状态,可参考如下代码:

@Entry
@Component
struct TextInputExample {
controller: TextInputController = new TextInputController()
@State inputValue: string = “”

build() {
Column() {
TextInput({ text: this.inputValue, placeholder: ‘input your word…’, controller: this.controller })
.placeholderColor(Color.Grey)
.placeholderFont({ size: 14, weight: 400 })
.caretColor(Color.Blue)
.width(‘95%’)
.height(40)
.margin(20)
.fontSize(14)
.fontColor(Color.Black)
.onChange((value: string) => {
this.inputValue = value
})

}
.width(‘100%’)
.height(‘100%’)
.onClick(()=>{
this.controller.stopEditing()
})
}
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进