Question / Problem:
How to add webview and load a website in it in android app using java.
Answer / Solution:
1. Add the webview control on the app xmlview.
2. add following code in the .java file
Note: dont forget to add teh internet permission in your AndroidManifest.xml file
now your site will be loaded in the webview.
Thanks
How to add webview and load a website in it in android app using java.
Answer / Solution:
1. Add the webview control on the app xmlview.
2. add following code in the .java file
Java:
// -----------------------------------------------
// Code to load a website in webview
// -----------------------------------------------
WebView webView = findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAllowFileAccess(true);
webSettings.getAllowFileAccessFromFileURLs();
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setBuiltInZoomControls(true);
// webView.setWebChromeClient(new WebChromeClient());
WebViewClient wc = new WebViewClient();
webView.setWebViewClient(wc);
webView.loadUrl("https://[your-site-address.com]");
XML:
<uses-permission android:name="android.permission.INTERNET" />
Thanks
Last edited: