Dinesh
Dinesh

Reputation: 965

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

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?

Upvotes: 0

Views: 1178

Answers (2)

Maverick
Maverick

Reputation: 11

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

Upvotes: 1

Mushtaq Jameel
Mushtaq Jameel

Reputation: 7083

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.

Upvotes: 0

Related Questions