HarmonyOS 鸿蒙Next inputText输入框怎么主动退出输入状态,失去焦点
HarmonyOS 鸿蒙Next inputText输入框怎么主动退出输入状态,失去焦点
inputText输入框怎么主动退出输入状态,失去焦点
3 回复
可以通过stopediting退出软件盘的编辑状态,可参考如下代码:
[@Entry](/user/Entry)
[@Component](/user/Component)
struct TextInputExample {
controller: TextInputController = new TextInputController()
[@State](/user/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()
})
}
}
试试这个:
import { BusinessError } from '[@kit](/user/kit).BasicServicesKit';
inputMethodController.hideTextInput((err: BusinessError) => {
if (err) {
console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`);
return;
}
console.log('Succeeded in hiding text input.');
});