HarmonyOS TextInput如何内容自适应?

TextInput 如何使输入内容自适应,默认一行展示,最多展示三行

阅读 492
1 个回答

当前的TextInput本身就是单行文本框。输入要多行输入框,请参考TextArea,https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-textarea-V5\#maxlines10

TextArea设置超过3行可以滚动显示,参考demo,textOverflow设置文本超长时的显示方式

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-text-V5\#textoverflow

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-text-V5\#示例1

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';
  controller: TextAreaController = new TextAreaController()
  build() {
    Column() {

      TextArea({
        text:'测试一下',
        placeholder: 'The text area can hold an unlimited amount of text. input your word...',
        controller: this.controller
      })
        .placeholderFont({ size: 16, weight: 400 })
        .width(336)
        .constraintSize({
          maxHeight: 75
        })
        .margin(20)
        .fontSize(16)
        .fontColor('#182431')
          // .maxLines(3)
        .focusable(true) // 组件是否获焦
        .showCounter(false)

    }.height('30%')
  }
}