textinput 文本框是否可以分段展示?

textinput 文本框是否可以分段展示 我们有一个手机号输入框,希望可以分段展示手机号。

HarmonyOS
2024-10-08 13:09:47
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

使用自定义键盘来支持,在自定义键盘中处理手机号码的格式。https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-textinput-V5#%E7%A4%BA%E4%BE%8B3

@Entry  
@Component  
struct TextInputExample {  
  controller: TextInputController = new TextInputController()  
  @State inputValue: string = ""  
  // 自定义键盘组件  
  @Builder CustomKeyboardBuilder() {  
    Column() {  
      Button('确认').onClick(() => {  
        // 关闭自定义键盘  
        this.controller.stopEditing()  
      })  
      Grid() {  
        ForEach([1,2,3,4,5, 6, 7, 8, 9, '空格',0,"删除"], (item:number|string) => {  
          GridItem() {  
            Button(item + "")  
              .width(110).onClick(() => {  
              this.inputValue+=item;  
              //逻辑处理inputValue  
            })  
          }  
        })  
      }.maxCount(3).columnsGap(10).rowsGap(10).padding(5)  
    }.backgroundColor(Color.Gray)  
  }  
  build() {  
    Column() {  
      TextInput({ controller: this.controller, text: this.inputValue })  
        // 绑定自定义键盘  
        .customKeyboard(this.CustomKeyboardBuilder()).border({ width: 1 })  
    }  
  }  
}
  • 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.
  • 33.
分享
微博
QQ
微信
回复
2024-10-08 16:54:47
相关问题
HarmonyOS TextInput全宽文本框怎么使用
378浏览 • 1回复 待解决
如何获取文本框里的文字宽度
3090浏览 • 1回复 待解决
如何拿到文本框文字的宽度数值
877浏览 • 1回复 待解决
HarmonyOS 如何获取文本框中光标高度
703浏览 • 1回复 待解决
文本组件是否支持分段设置字体样式
2838浏览 • 1回复 待解决
HarmonyOS TextInput是否支持富文本
912浏览 • 1回复 待解决
怎么让文本框在禁用时变灰?
302浏览 • 1回复 待解决
是否可以自定义权限弹文字
2514浏览 • 1回复 待解决
HarmonyOS textInput 如何清空输入
886浏览 • 2回复 待解决
AES加解密长字符串是否需要分段
994浏览 • 1回复 待解决