可以通过在外面的容器绑定点击事件TextInputController.stopEditing去实现
直接上代码
@Entry
@Component
struct TextInputExamplesTwo{
controller: TextInputController = new TextInputController()
build() {
Column() {
Scroll() {
Column({space: 20}) {
TextInput({controller: this.controller, placeholder: 'user define password'})
.type(InputType.Password)
.width("90%")
.height(60)
}
.focusable(true)
.alignItems(HorizontalAlign.Start)
}
}
//失去焦点核心代码
.onClick(()=>{
this.controller.stopEditing()
})
.width('100%')
.height('100%')
}
}