0

I tried to create a text with separate paragraphs in a string resource. The Android documentation states that <p></p> is supported, but it is ignored. I can insert a \n, but that doesnt insert any space between the paragraphs. I use \n\n as a work around, but 2 newlines simply wastes too much vertikal space.

Can I post-process the string in kotlin to fix that?

<string name="lorem_ipsum"><p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
<p>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
<p>At vero eos et accusam et justo duo dolores et ea rebum.</p>
<p>Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p></string>

This is how it should look like: HTML rendering

This is the result: enter image description here

2
  • have you tried with HTML.fromHtml(); ? Commented Jun 19, 2022 at 13:43
  • Have you considered using a WebView instead of a TextView? Else the CSS support is rather limited. The HTML markup is not being ignored, but you cannot apply p {} CSS styles to it. Commented Jun 19, 2022 at 14:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.