Skip to content

Instantly share code, notes, and snippets.

@ionull
Created January 19, 2015 12:47
Show Gist options
  • Save ionull/ee154c18360a5324b6ad to your computer and use it in GitHub Desktop.
Save ionull/ee154c18360a5324b6ad to your computer and use it in GitHub Desktop.
Add local style to remote html in Android WebView
new Thread(new Runnable() {
@Override
public void run() {
try {
Connection connection = Jsoup.connect(url);
final Document doc = connection.get();
Element head = doc.head();
String htmlData = "<link rel=\"stylesheet\" type=\"text/css\" href=\"file:///android_asset/style.css\" />";
head.append(htmlData);
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
URL u = new URL(url);
webView.loadDataWithBaseURL(u.getProtocol() + ":" + u.getHost(), doc.html(), "text/html", "UTF-8", null);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment