Reputation:
I want use webView
in my application and I should set justify texts into of webview
.
I write below code for set image size, but how can I add justify text into this code :
private String getHtmlData(String bodyHTML) {
String head = "<head><style>img{max-width: 100%; width:auto; height: auto;}</style></head>";
return "<html>" + head + "<body>" + bodyHTML + "</body></html>";
}
set html to webview :
content_newsWebView.loadDataWithBaseURL(null, getHtmlData(response.body().getData().getDescription())
, "text/html", "utf-8", null);
How can I add justify text into webView
?
Upvotes: 1
Views: 2171
Reputation: 20
if someOne still looking for answer
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
view.loadUrl(
"javascript:document.body.style.setProperty(\"text-align\", \"justify\");"
);
}
});
Upvotes: 0
Reputation: 179
Same as in html
return "<html>" + head + "<body style='text-align: justify;'>" + bodyHTML + "</body></html>";
Upvotes: 3