gpt4 book ai didi

android - HTML 字符串未在 TextView 中呈现

转载 作者:太空狗 更新时间:2023-10-29 13:51:33 26 4
gpt4 key购买 nike

我有一个这样的json数据

{
"user_id": "27",
"notification": "<a>There is package wiating for you to pick from <font style="color: blue;"> #Surat</font> to <font style = "color: blue;"> #Adajan, Surat, Gujarat, India</font> </a>",
},
{
"user_id": "27",
"notification": "<a>There is package wiating for you to pick from <font style="color: blue;"> #majuraget, surat</font> to <font style = "color: blue;"> #pal, surat</font> </a>",
},
{
"user_id": "27",
"notification": "<a>There is package wiating for you to pick from <font style="color: blue;"> #majuraget, surat</font> to <font style = "color: blue;"> #pal, surat</font> </a>",
},
{
"user_id": "27",
"notification": "<a>There is package wiating for you to pick from <font style="color: blue;"> #majuraget, surat</font> to <font style = "color: blue;"> #pal, surat</font> </a>",
}

我正在 Textview 中呈现此通知字符串,但它不起作用。

这是我试过的

Spanned value = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {

value = Html.fromHtml(notifications.getTitle(), Html.FROM_HTML_MODE_COMPACT);
holder.txtTitle.setMovementMethod(LinkMovementMethod.getInstance());
holder.txtTitle.setText(value);

}else {
value = Html.fromHtml(notifications.getTitle());
holder.txtTitle.setMovementMethod(LinkMovementMethod.getInstance());
holder.txtTitle.setText(value);
}

我也试过这个library :

Spanned fromHtml = HtmlCompat.fromHtml(context, notifications.getTitle(), 0);
holder.txtTitle.setMovementMethod(LinkMovementMethod.getInstance());
holder.txtTitle.setText(fromHtml);

但这些都不起作用。

这是我得到的输出:

enter image description here

这就是我所期望的

enter image description here

最佳答案

尝试像这样修改通知字符串:

{
"user_id": "27",
"notification": "<a>There is package wiating for you to pick from <font color='blue'> #majuraget, surat</font> to <font color='blue'> #pal, surat</font> </a>"
}

关于android - HTML 字符串未在 TextView 中呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46405424/

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