使我有這樣HTML字符串不是TextView的
{
"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>",
}
一個JSON數據I M渲染的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);
,但這些都不是工作。
這是我得到的輸出:
,這是我所期望
你有沒有試過這個https://stackoverflow.co m/questions/42389878/android-app-not-rendering-html-tags-very-well – Ankita