首页 > 解决方案 > 在 Android 设备中运行应用程序时字符串格式不起作用

问题描述

我有一个像这样格式化的字符串。

<string name="instructions" formatted="true">
    Follow these instructions.
    <br/><br/>
    1. Step 1.
    <br/><br/>
    2. Step 2.
    <br/><br/>
    3. Step 3.
</string>

在设计器预览中,它看起来像这样。

在此处输入图像描述

当我在模拟器或真正的 Android 设备中运行它时,它看起来像这样。

在此处输入图像描述

如何让真实设备看起来像设计器预览?

标签: androidandroid-studioandroid-resources

解决方案


使用\n而不是<br/>像下面这样:

    <string name="instructions" formatted="true">
    Follow these instructions.
    \n\n
    1. Step 1.
    \n\n
    2. Step 2.
    \n\n
    3. Step 3.
    </string>

推荐阅读