I saw a lot of post and suggestions saying to use "utf-8", and I am using it but getting some extra characters in the web view.
mWebView.loadDataWithBaseURL("file://" + file1, htmltext, "text/html", "utf-8", null);
I also tried
WebSettings settings = mWebView.getSettings();
settings.setDefaultTextEncodingName("utf-8");
Related
I have a problem when load html5 into webview.
My app in first build play video success but when i clear/kill app open again, webview not play video when click play.
Html5
<video src="url.mp4" controls poster="thumbnail.jpg" style="max-width: 100%;">Download video</video>
Source load webview
WebView webView = new WebView(context);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new WebViewClient());
String html = "<html><head><link rel='stylesheet' href='file:///android_asset/css/style.css'></head><body>"
+ htmlElement.getContent()
+ "</body></html>";
webView.loadDataWithBaseURL("file:///android_asset/", html, mimetype, encoding, "");
I research and try fix this issue but not success
https://stackoverflow.com/questions/3815090/webview-and-html5-video
https://issuetracker.google.com/issues/36935939 v.v..
Anyone has the same my problem? Thanks.
Try this :-
DashBoardFragment2.java :-
https://drive.google.com/file/d/1UREa7uGrQYcF-ABzPktBSjUcOPtytxSC/view?usp=sharing
dashboard.xml :-
https://drive.google.com/file/d/1LlgbdSe-9bgUU5lsGZUGOX3Tg7bnVpzH/view?usp=sharing
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.
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
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");
how can I change text direction to the Right to Left in webview ?
This is my code
WebView web = (WebView) findViewById(R.id.web);
web.getSettings().setJavaScriptEnabled(true);
web.loadDataWithBaseURL("", myhtml, "text/html", "UTF-8", "");
I think that you need to change the dir="RTL in your HTML code.
for example:
<body dir="rtl">
<p>Some Text that will be RTL aligned</p>
</body>
WebView just allow you to view webpages but doesn't change the text direction. That only depends on the HTML markup in the web page.
If it still doesn't work, you might have issues in your HTML. You can share your code here and I can try to help you further.
Tom.
it work for me:
desc.loadDataWithBaseURL("http://www.atfonline.ir/", "<html dir=\"rtl\" lang=\"\"><body>" + outhtml + "</body></html>", "text/html", "UTF-8", null);
I have an info.html for my App which is in a webview. info.html is encoded with UTF-8.
I want talkback to vocalize the text in it however it fails in some non-english characters.
String infoURL = "file:///android_asset/info.html";
WebView view = (WebView) theAct.findViewById(R.id.webview);
view.loadUrl(infoURL);
I used also this, which failed:
String infoURL = "file:///android_asset/info.html";
WebSettings settings = view.getSettings();
settings.setDefaultTextEncodingName("utf-8");
view.loadUrl(infoURL);
or:
...
view.loadDataWithBaseURL(infoURL, null, "text/html", "utf-8",null);
Make sure the file itself is saved as UTF-8, sometimes is not sufficient to specify
<meta charset="utf-8">
inside html file
I am planning to display images from SD card in a webview in order to take advantage of he built in zoom capabilities of webview. However, I am facing an issue with displaying images that are bigger than screen size (e.g. 1800x1200) to fit the screen initially, like in an ImageView. I want the image to be displayed in full at first and provide zoom control to the users.
I have tried using WRAP_CONTENT for webview's width and height, but that does not work.
Any ideas?
Following is a code snippet I am using:
String path = getRealPathFromURI(mUriList.get(0)); // this gets the file path
webView = (WebView) findViewById(R.id.WebView01);
WebSettings settings= webView.getSettings();
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
webView.loadUrl("file://" + path);
private WebView mWebView2;
mWebView2 = (WebView)findViewById(R.id.webview);
mWebView2.getSettings().setJavaScriptEnabled(true);
mWebView2.getSettings().setLoadWithOverviewMode(true);
mWebView2.getSettings().setUseWideViewPort(true);
mWebView2.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView2.setScrollbarFadingEnabled(true);
mWebView2.loadDataWithBaseURL("file:///android_asset/", "<img src=\"banner5.png\" height=\"98%\" width=\"100%\"/>", "text/html", "utf-8", null);
Images are in the assets folder
If you write your HTML correctly, you don't have to do any "setLoadWithOverviewMode", "setUseWideViewPort" or "setInitialScale". And there is absolutely no reason to enable JavaScript.
This one line worked for me:
webView.loadDataWithBaseURL("file://" + directory,
"<img src=\"" + name + "\" width=\"100%\"/>", "text/html", "utf-8", null);
The underlining HTML code is:
<img src=YourImage.png width="100%" />, by not setting a height, its aspect ratio will be kept.
That did the trick for me:
webView.setInitialScale(30);
WebSettings webSettings = webView.getSettings();
webSettings.setUseWideViewPort(true);
WebSettings settings = webView.getSettings();
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true)