I have a string formatted like this.
<string name="instructions" formatted="true">
Follow these instructions.
<br/><br/>
1. Step 1.
<br/><br/>
2. Step 2.
<br/><br/>
3. Step 3.
</string>
In the designer preview, it looks like this.
When I run it in an emulator or real Android device, it looks like this.
How can I get the real device to look like the designer preview?
2
Answers
Use
n
instead of<br/>
like below:Another approach, you can try to use Html.fromHtml() which is in Android SDK. For an instance, like this: (Kotlin extension method)
In strings.xml, the string looks like this:
Note: I trim the spaces, you can add what you want, such as color
How to use it?
In Fragment or Activity, using getString(R.string.instructions).toHtml() to get the Spanned and display it on UI.
Don’t worry, Spanned extends from CharSequence.