applibgroup / HarmonyOS-Knowledgebase

This repository contains code samples of HarmonyOS Training
Apache License 2.0
15 stars 6 forks source link

How to add a new line in Text Control as input via String Resource or Java Code? #88

Closed kanaksony closed 2 years ago

kanaksony commented 2 years ago

I have some long text to input in a Text control that is going out of the screen. I want to make it multiline in same text. How can I do that via JSON String Resource and from java code?

I have already tried appending \n (newline) character but it works neither via JSON nor via code

Additional information

Developer Platform: Windows DevEco Studio version: 2.1.0.501 SDK API version: 5 SDK version: 2.1.1.21 Device: Simulator (Tablet Matpad Pro)

kanaksony commented 2 years ago

I found the answer, we have to add a property ohos:multiple_lines="true" in the Text component, and then the text will automatically appear in multiple lines. Also appending a new line character starts work.