简体   繁体   中英

android : fromhtml is leaving font details in the string

I am converting html string using Html.fromHtml(sBody) to add it to an edittext . I need editext , so I cant use webview to loaddata .

et.setText(Html.fromHtml(sBody));

What I see is the converted text has some font detail added in the beginning . sample data is :

!-- /* Font Definitions */ @font-face   {font-family:"Cambria Math";    panose-1:2 4 5 3 5 4 6 3 2 4;} @font-face   {font-family:Calibri;   panose-1:2 15 5 2 2 2 4 3 2 4;} @font-face

how can I remove this .

please help

how can i remove this

Remove it yourself from the HTML before passing it to Html.fromHtml() .

Html.fromHtml() does not handle all possible HTML, nor is it meant to. It only deals with the subset of HTML tags that are relevant for TextView and its subclasses. Other stuff -- in this case, some inline CSS -- it is going to largely ignore, which may leave it as visible text.

So, find yourself an HTML parser and strip out unnecessary cruft.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM