gpt4 book ai didi

java - 为什么 Html.fromHtml 不适用于 Android 中的 String?

转载 作者:行者123 更新时间:2023-12-01 16:26:06 27 4
gpt4 key购买 nike

enter image description here

一个字符串值来 self 的 firebase:

if (task.isSuccessful()) {
// binding.contentMain.noData.setVisibility(View.GONE);
for (QueryDocumentSnapshot document : Objects.requireNonNull(task.getResult()))
postMap.putAll(document.getData());

try {
if (postMap != null)
//binding.desc1.setText(Objects.requireNonNull(postMap.get(CONTENT)).toString());
binding.desc1.setText(Html.fromHtml(Objects.requireNonNull(postMap.get(CONTENT)).toString()));
} catch (Exception e) {
e.printStackTrace();
}
}

现在,我将告诉您 Firestore 中的 String 内部有什么内容,实际上我只是在 Firestore 集合中手动编写为 String 字段。:

This is the first text. \n\n This is a second text. \n This is the third text. \n\n Done. \n

确保上面的行只是一个字符串/firestore 字段。

在 firestore 中,我将上述值存储为 String,并获取该值并在 Android 中显示它。但它并没有采取新的路线。相反,它显示书写的\n 以及其他字符。

我尝试过使用和不使用 HTML。与\n 和\r\n。

更新:您可以在下图中看到我如何在 Firestore 中存储。 https://drive.google.com/open?id=19yry9top_W8LREw5SEaZKWYWSlnCP1io

最佳答案

在 firestore 中,您需要在 n 之前放置两个 \ 来添加新行。

如果您要从用户处获取数据或从文件中读取数据,请在存储数据之前添加此行:

str.replaceAll("\\n", "\n");

关于java - 为什么 Html.fromHtml 不适用于 Android 中的 String?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62144628/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com