Created
January 19, 2015 12:47
-
-
Save ionull/ee154c18360a5324b6ad to your computer and use it in GitHub Desktop.
Add local style to remote html in Android WebView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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