HarmonyOS TextInput如何通过代码获取焦点

如何实现在输入好手机号后点击回车(目前的表现是收起软键盘),跳转到下一个输入框继续输入。

HarmonyOS
2024-12-25 14:04:22
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

参考以下示例:

import promptAction from '@ohos.promptAction';

@Entry
@Component
struct RequestFocusExample {
  @State selectId: string = 'A'
  @State mobileNo: string = 'xxx'

  build() {
    Column({ space: 20 }) {
      Row({ space: 5 }) {
        TextInput({ text: this.mobileNo })
          .width(200).height(50).fontColor(Color.Black)
          .key('A')
        Button("编辑手机号")
          .width(80).height(35).fontColor(Color.White)
          .onClick(() => {
            let res = focusControl.requestFocus('A') // 使选中的this.selectId的组件获焦
            if (res) {
              promptAction.showToast({ message: 'Request success' })
            } else {
              promptAction.showToast({ message: 'Request failed' })
            }
          })
      }
    }.width('100%').margin({ top: 20 })
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-25 16:11:24
相关问题
HarmonyOS TextInput自动获取焦点问题
824浏览 • 1回复 待解决
HarmonyOS TextInput组件无法自动获取焦点
1044浏览 • 1回复 待解决
TextInput组件获取焦点的几种场景
4004浏览 • 1回复 待解决
HarmonyOS TextInput焦点问题
1116浏览 • 1回复 待解决
HarmonyOS 如何TextInput获得输入焦点
854浏览 • 1回复 待解决
HarmonyOS TextInput 取消默认焦点
1114浏览 • 1回复 待解决
如何监听TextInput是否获得焦点
2596浏览 • 1回复 待解决
TextInput如何取消自动获得焦点
1342浏览 • 1回复 待解决
HarmonyOS TextInput无法取消焦点
960浏览 • 1回复 待解决
HarmonyOS 如何通过代码获取appID
825浏览 • 1回复 待解决
HarmonyOS 如何通过代码获取应用名称
809浏览 • 1回复 待解决
HarmonyOS Image获取焦点和失去焦点失效
614浏览 • 1回复 待解决
HarmonyOS TextArea获取焦点
559浏览 • 1回复 待解决