How to apply CSS into WebView for remote html(url)?

混江龙づ霸主 提交于 2019-12-11 19:24:13

问题


I have a web page for example

"example.google.com/login?"

I have loaded this url into the WebView using WebView.loadUrl() method. I have the css for this webpage and saved it in under the assets folder. Now I want to apply custom css for this remote html. How do I achieve that?

I have used loadDataWithBaseurl() but it didn't help. How can I fix this problem?

Is css only applying for a local html file that is stored in assets folder?


回答1:


Had the same issue here, but worked around the issue! 1.) Cut out original CSS with JSOUP. 2.) Provide your costumized CSS thru your own webserver 3.) Add CSS entry with JSOUP Load the HTML in WebView with your own hosted CSS.

            doc = Jsoup.connect(MyTaskParams.base_URL+MyTaskParams.sub_URL).get();

            doc.head().getElementsByTag("link").remove();
            doc.head().appendElement("link").attr("rel", "stylesheet").attr("type", "text/css").attr("href", "http://www.unden.at/zzzz/at.unden.android.screen.css");

Visits to my Homepage are Welcome




回答2:


The WebView.loadUrl() should give you an idea of what is happening in the method call.

You can load a page which has all the style code referenced from the page itself or within it as some inline or in page styles.

You can't load different Stylesheets from the assets folder for remote URL's because they come in as a Read-Only input stream, so there is not much you can do about it.



来源:https://stackoverflow.com/questions/17473701/how-to-apply-css-into-webview-for-remote-htmlurl

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