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.

Bixms
  • 771
  • 1
  • 7
  • 16

2 Answers2

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

Community
  • 1
  • 1
Horrorgoogle
  • 7,858
  • 11
  • 48
  • 81
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");
ashish.n
  • 1,234
  • 14
  • 30
  • Give me some detials about **MyTaskParams.base_URL** and **MyTaskParams.sub_URL**. and what is the type of doc. – Bixms Mar 20 '15 at 08:16