1

I have css file url-> http:...../test.css.

Now I have html string htmlString=:

<div class=\"detailInfo\">\r\n<table class=\"leftFloat\">\r\n<tbody>\r\n<tr>\r\\r\n<\/tbody>\r\n<\/table>\r\n<\/div>*

Then,

                webView=(WebView) findViewById(R.id.webViewDetials);
                webView.setBackgroundColor(0x00000000);
                webView.getSettings().setJavaScriptEnabled(true);
                webView.loadDataWithBaseURL("http://.../css/test.css", attributes, mime, encoding, null);

I don't know to render above url css in below htmlString html string. any idea.

There are lots of example get css from assets folder but i cannot find load css from url.

4
  • i dont get it. so, you want to inject css into html? Commented Mar 20, 2015 at 6:23
  • Yes, i want to inject above url css in to my html. Commented Mar 20, 2015 at 6:24
  • that, some serious security leak. but, you can just change style of 1 attribute or more using webview.sendJavascript(), rather than inject css file Commented Mar 20, 2015 at 6:27
  • Look at first answer Here Commented Mar 20, 2015 at 7:02

2 Answers 2

1

I have faced such type of problem, May be helpful for you,

                webView=(WebView) findViewById(R.id.webView1);

                webView.getSettings().setJavaScriptEnabled(true);
                StringBuilder sb = new StringBuilder();
                sb.append("<HTML><HEAD><LINK href=\"http://test.com/css/test.css\" type=\"text/css\" rel=\"stylesheet\"/></HEAD><body>");
                sb.append(attributes.toString());
                sb.append("</body></HTML>");
                webView.loadDataWithBaseURL(null, sb.toString(), "text/html", "utf-8", null);

Hopefully, it works.

related Links:

and github plugin: https://github.com/NightWhistler/HtmlSpanner

Android WebView renders blank/white, view doesn't update on css changes or HTML changes, animations are choppy

Sign up to request clarification or add additional context in comments.

Comments

0

use Jsoup to cut the CSS t

 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.xyz.cm/pages/myown.css");

1 Comment

Give me some detials about MyTaskParams.base_URL and MyTaskParams.sub_URL. and what is the type of doc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.