我的strings.xml中有以下行:
<string name="test_string">This is a <u>test</u></string>
在我的活动xml中,我在TextView中引用了这个字符串:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/test_string" />
奇怪的是,当我在我的设备上运行应用程序(小米Mi A1,Android 8.0)时,< u>之前的空间.也有下划线.注意“a”和“test”之间带下划线的空格(来自实际设备的屏幕截图):
我也尝试在strings.xml中使用以下内容:
<string name="test_string">This is a <u>test</u></string>
但结果是一样的.有任何想法吗?
解决方法:
我能够在我的模拟器上重现这一点.要解决,我更改了字符串资源,如下所示:
<string name="underline">this is a <u>test</u></string>
然后,我不是简单地将字符串设置为我的TextView,而是首先通过Html.fromHtml()运行它:
TextView text = findViewById(R.id.text);
String withMarkup = getString(R.string.underline);
text.setText(Html.fromHtml(withMarkup));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。