Reputation: 5269
i have a json data like this
{
"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>",
}
i m rendering this notification string in Textview but its not working.
this is what i tried
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);
}
i also tried this library:
Spanned fromHtml = HtmlCompat.fromHtml(context, notifications.getTitle(), 0);
holder.txtTitle.setMovementMethod(LinkMovementMethod.getInstance());
holder.txtTitle.setText(fromHtml);
but none of this is work.
this is what i get as output:
and this is what i expect
Upvotes: 3
Views: 247
Reputation: 2803
Try modifing the notification string like this:
{
"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>"
}
Upvotes: 1