HarmonyOS TextInput在输入状态下,如何让点击界面任何地方,收起键盘?

HarmonyOS
2024-12-25 07:37:42
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
shlp

请参考以下示例:

import { inputMethod } from '@kit.IMEKit';
@Entry
@Component
struct LeftRightTest {
  @State a:boolean =true;
  controller: TextInputController = new TextInputController()
  build() {
    Column() {
      TextInput({placeholder: '请输入内容'})
        .backgroundColor(Color.Orange)
        .onTouch(()=>{
          this.a=true;
        })
      Button('点我')
      TextInput({placeholder: '请输入内容'})
        .backgroundColor(Color.Orange)
        .onTouch(()=>{
          this.a=true;
        })
    }
    .height('100%')
    .width('100%')
    .onTouch(() => {
      if (this.a!=true) {
        // 收起键盘
        let inputMethodController = inputMethod.getController();
        inputMethodController.stopInputSession()
      }
      this.a=false
    })
  }
}
分享
微博
QQ
微信
回复
2024-12-25 10:07:15
相关问题
TextInput组件输入状态下隐藏光标
1674浏览 • 1回复 待解决
点击 HVD Manager没任何界面
11215浏览 • 6回复 已解决
HarmonyOS 如何TextInput获得输入焦点
184浏览 • 1回复 待解决
如何设置组件不同状态下的样式
2167浏览 • 1回复 待解决
HarmonyOS如何收起键盘
506浏览 • 1回复 待解决
HarmonyOS 键盘收起
163浏览 • 1回复 待解决
何设置组件不同状态下的样式
2302浏览 • 1回复 待解决
HarmonyOS 横屏状态下获取组件的宽高
713浏览 • 1回复 待解决