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
    })
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
分享
微博
QQ
微信
回复
2024-12-25 10:07:15
相关问题
TextInput组件输入状态下隐藏光标
2265浏览 • 1回复 待解决
点击 HVD Manager没任何界面
11966浏览 • 6回复 已解决
HarmonyOS 如何TextInput获得输入焦点
832浏览 • 1回复 待解决
如何设置组件不同状态下的样式
2656浏览 • 1回复 待解决
HarmonyOS如何收起键盘
846浏览 • 1回复 待解决
HarmonyOS 键盘收起
520浏览 • 1回复 待解决
何设置组件不同状态下的样式
2809浏览 • 1回复 待解决
HarmonyOS 横屏状态下获取组件的宽高
1320浏览 • 1回复 待解决