How to add local css file to a page in WebView? - android

So, I have a WebView showing page from url:
WebView webView = (WebView) findViewById(R.id.showContentWebView);
String url = "http://edition.cnn.com/2014/02/05/sport/shaun-white-sochi-slopestyle/index.html";
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(url);
And I also have a file "style.css" in my assets folder. How can I display the page in WebView with style.css connected?

I think this is possible only if you somehow process the HMTL content, adding a link to your css file. In this case, please refer to this question.

Related

Stripe.js credit card input form invisible in Webview

I was trying to test if it is possible to integrate stripe js in a website and load that site in an android Webview to proceed for payment. I was using this link https://github.com/stripe/elements-examples to load that in Webview like this:
WebView browser = (WebView) findViewById(R.id.webview);
browser.loadUrl("https://stripe.github.io/elements-examples/");
Everything is loading in the Webview except the credit card field is not there. Either it is not visible or it can not be editable. Why is that?
Try to add below code to enable Javascript in your Webview:
WebSettings webSettings = browser.getSettings();
webSettings.setJavaScriptEnabled(true);

Webview Android does'nt load whole content from a large html file

I have a very large html file(around 10k lines of only text). When I use Webview to load this html content, it shows only around few hundreds and remaining space is blank(white space). Can someone help me with this issue? Thank You.
Following is my code:
WebView mWebView;
mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("file:///android_asset/test.html");//test.html in assets folder
I also try with webView.setLayerType(WebView.LAYER_TYPE_HARDWARE, null) or webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null) but it does'nt help.
I just found solution for my issue with Webview. The reason Webview can't display whole content of html file because the html is not well constructed, some html tag like <abc#.com> will not be read by Webview. So I convert content to correct html form then it works.

Online images in local Webview page in Android

I have a webview showing a local html page resource in a string like this:
<p>Hi.</p>
<p><img alt="" src="http://ADRESS.COM/image.jpg" style="height:300px; width:400px" /></p>
and doing that with this code:
WebView web = (WebView) findViewById(R.id.web);
web.getSettings().setJavaScriptEnabled(true);
web.loadDataWithBaseURL("",notice,"text/html","UTF-8","");
The page contains some images with online src. but in android WebView the images doesn't load. (in chrome it works).
What I should do?
thanks.
Add these two lines in your code.
web.getSettings().setLoadsImagesAutomatically(true);
web.getSettings().setDomStorageEnabled(true);
Instead of using web.loadDataWithBaseURL("",notice,"text/html","UTF-8",""); simply load your website url as follows
web.loadUrl("http://www.google.com");
if you want load your local html page. Create asset directory android then put your html file in asset folder and and set it as follows
web.loadUrl("file:///android_asset/yourFile.html");

How to display image in webview android?

I am working on android. I am trying to display the page data in webview. i.e actually i am getting the data from php webservice. The result of that php webservice is
a document with images and text.(If we right click on that page and view page source it is all the html data). But now what I am doing is I am setting the php link to the webview. So now, it is display fine in webview (same as how it is displaying in webpage). But now the document contains some images which are displaying in website but those images are not displaying in webview. What should I do now? Please help me in this regard.
Code:
WebView webview;
WebSettings settings;
link = "http://.............../page.php?test=123&test1=345"
webview = (WebView) findViewById(R.id.webView1);
settings = webview.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setPluginState(PluginState.ON);
webview.loadUrl(link);
please add this line,
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(PluginState.ON);

Android loadUrl unable to load site

My webview will works for a site such as Google.com, however, the specific page will not load.
Simply displays subscribe to feedburner (I made this site to reflect a converted news feed)
This specific webpage will display correctly in an Iphone UIWebView, but not for Android.
Some code
WebView rss = (WebView) findViewById(R.id.webviewRSS);
rss.loadUrl("www.newmanu.edu/newmannews");
Check out the source of "www.newmanu.edu/newmannews", you have to activate javascript.
from http://developer.android.com/guide/webapps/webview.html
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
Add http:// or https:// before URL.
Try this.
rss.loadUrl("http://www.newmanu.edu/newmannews");
Or
rss.loadUrl("https://www.newmanu.edu/newmannews");

Categories

Resources