HarmonyOS TextArea组件如何设置scrollable属性为true?

maxLine为3,超过3行缺无法滑动。通过ArkUI Inspector查看,TextArea组件的scrollable属性为false。如何设置为true

阅读 439
1 个回答

TextArea组件,用作输入框输入时,输入的内容大于当前的高度时,scrollable属性为true,但是作为输出文本时,不支持设置可滑动,

参考demo:

@Entry
@Component
struct TextAreaExample {
  @State text: string = ''
  @State text1: string = 'ajkhafhajkfhalfhalfhakfhak;ha;kghaghafjhfajfhalfhlajfga\n' +
    'ljfgaljgfalgfha;kgha;hg;ahga;hgai;\n' +
    'ghae;ihgfafajjfhajlghalgha;gha;gha;kgha;lghiahga\n' +
    'ioghaiohgaiohgaoighaipghaipghaighaighaighaiohgai;gha;gkgaggaagag'
  @State positionInfo: CaretOffset = { index: 0, x: 0, y: 0 }
  controller: TextAreaController = new TextAreaController()

  build() {
    Column() {
      TextArea({
        text: this.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)
        .height(56)
        .margin(20)
        .fontSize(16)
        .maxLines(3)
        .fontColor('#182431')
        .backgroundColor('#FFFFFF')
        .onChange((value: string) => {
          this.text = value
        })
      TextArea({ text: this.text1, })
        .maxLines(3)
    }.width('100%').height('100%').backgroundColor('#F1F3F5')
  }
}