strings.xml:如何从<u>标记之前的空格中删除下划线?

Igo*_*gor 3 android textview android-styles

我的内容如下strings.xml:

<string name="test_string">This is a <u>test</u></string>
Run Code Online (Sandbox Code Playgroud)

在我的活动xml中,我在TextView中引用了这个字符串:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/test_string" />
Run Code Online (Sandbox Code Playgroud)

奇怪的是,当我在我的设备上运行应用程序(小米Mi A1,Android 8.0)时,前面的空格<u>也加下划线.注意"a"和"test"之间带下划线的空格(来自实际设备的屏幕截图):

设备

我也尝试过使用以下内容strings.xml:

<string name="test_string">This is a&#032;<u>test</u></string>
Run Code Online (Sandbox Code Playgroud)

但结果是一样的.有任何想法吗?

Ben*_* P. 5

我能够在我的模拟器上重现这一点.要解决,我更改了字符串资源,如下所示:

<string name="underline">this is a &lt;u>test&lt;/u></string>
Run Code Online (Sandbox Code Playgroud)

然后,我不是简单地将字符串设置为我的TextView,而是Html.fromHtml()先运行它:

TextView text = findViewById(R.id.text);
String withMarkup = getString(R.string.underline);
text.setText(Html.fromHtml(withMarkup));
Run Code Online (Sandbox Code Playgroud)