3

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:

enter image description here

and this is what i expect

enter image description here

1

1 Answer 1

1

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>"
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks.. its worked.. so the styles is not rendering on android side.. only attribute does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.