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

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

HarmonyOS
2024-05-06 23:14:46
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
Heiang

可以通过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() 
}) 
} 
} 
分享
微博
QQ
微信
回复
2024-05-07 15:58:05
相关问题
js如何清空一个input 输入框的内容
6375浏览 • 1回复 待解决
H5页面输入框自动获焦弹起软键盘
596浏览 • 1回复 待解决
ets的text input手动控制获得和失去焦点
3085浏览 • 1回复 待解决