2017-09-25 2 views
3

Ich habe ein json Daten wie dieseHTML-String rendert nicht in 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>", 
} 

i m Rendering diese Benachrichtigung Zeichenfolge in Textview, aber es funktioniert nicht.

das, was ich

versucht ist
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);  
     } 

Ich habe versucht, auch diese library:

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

aber nichts davon ist die Arbeit.

das ist, was ich als Ausgabe erhalten:

enter image description here

und das ist, was ich

enter image description here

+0

Hast du dieses https://stackoverflow.co versucht m/questions/42389878/android-app-nicht-rendering-html-tags-very-well – Ankita

Antwort

1

Versuchen modifing die Benachrichtigung Zeichenfolge wie folgt erwartet:

{ 
"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>" 
} 
+0

Danke .. es hat funktioniert .. so dass die Stile nicht auf Android Seite Rendern .. nur Attribut tut. –

+0

Gern geschehen. Ich bin froh, dass ich geholfen habe :) – Laura