- Get link
- X
- Other Apps
Hello Guys, welcome again here i am again with another exciting android tutorial with webview. If you want to load your website url inside your application or you want to make android application without more programming in android you can just load your website into your android application using Webview.
After that put below code into onCreate method of your mainactivity.java file.
and below code to outof the onCreate method.
That's it by doing this much you can convert your website into android application.
Here is the exaple for the same.
First of all create new project in android studio and follow below.
You need to add below line to manifest.xml file for internet permission.
<uses-permission android:name="android.permission.INTERNET" />
Put below xml code to your layout file.
<WebView android:id="@+id/webView1" android:layout_height="match_parent" android:layout_width="match_parent" />
WebView webview; webview = (WebView) findViewById(R.id.webView1); WebSettings websettings = webview.getSettings(); websettings.setJavaScriptEnabled(true); webview.loadUrl("your url here"); webview.setHorizontalScrollBarEnabled(false); webview.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); webview.setWebViewClient(new MyWebViewClient());
public class MyWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView webview, String url){ webview.loadUrl(url); return true; } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { view.loadUrl("file:///android_asset/errorpage.html"); } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { //can show loader herer } @Override public void onPageFinished(WebView view, String url) { //hide loader onpagefinished } }
Happy Coding!
Thanks.
Comments
Post a Comment