Android - Characters such as å,ä,ö do not render correctly in WebView

青春壹個敷衍的年華 提交于 2020-01-15 12:02:53

问题


I am using the following code to render my webview in android -

webview.loadDataWithBaseURL(null, "Subject: "+ getSubject() +" Content: "+ getContent() , "text/html" , "UTF-8", "");

The subject and content that I receive from the server are UTF encoded and show wrongly as Ã¥,ä,ö in the log and on screen. However in iOS webview they show up correctly as å,ä,ö. How do I get them to show as å,ä,ö in android as well?


回答1:


make sure the content you recieve, in tag <head> use like this: <meta charset="UTF-8" >

Sorry for my English. :)




回答2:


I think it's more of a font problem than code itself. Try putting DejaVuSans.ttf font instead of DroidSansFallback.ttf on the android itself. It should fix it. I'd search forum.xda-developers.com for a solution.




回答3:


It was due to how I was retrieving the message from the server. I was reading the Http response character by character so it broke up the encoding. When I started reading line by line it worked fine!



来源:https://stackoverflow.com/questions/9485384/android-characters-such-as-%c3%a5-%c3%a4-%c3%b6-do-not-render-correctly-in-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!