#鸿蒙通关秘籍#TextInput组件如何根据输入内容改变组件本身的长度?

HarmonyOS
2024-12-11 10:10:34
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
网络小天才
@Entry
@Component
struct ImagePreview {
    @State inputText: string = '';
    @State inputWidth: number = 400;
    controller: TextInputController = new TextInputController()
    build() {
        Row() {
            Column() {
                TextInput({placeholder:'请输入文本',text:`$$this.inputText`,controller:this.controller})
                .width(this.inputWidth+'px')
                .onChange(()=>{
                    if(this.controller.getTextContentRect().width>200){
                        this.inputWidth = this.controller.getTextContentRect().width+150
                    }
                    else{
                        this.inputWidth = 400
                    }
                })
            }
        }
        .width('100%')
        .height('100%')
    }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-11 11:43:24
相关问题
HarmonyOS TextInput如何阻止其输入内容
1228浏览 • 1回复 待解决
HarmonyOS TextInput输入内容限制
1491浏览 • 1回复 待解决
如何监听输入输入内容变化?
1335浏览 • 1回复 待解决
HarmonyOS hilog输入内容过长
798浏览 • 1回复 待解决
如何过滤textinput组件内容
1232浏览 • 1回复 待解决