How to create a WebView app in android studio | Part 1

How to create a WebView app in android studio | Part 1


Hi. Today i'm goint show you How to create a WebView app in android studio. I show you how to or which codes you have place on android sudio and where.

Step 1
  • Creat a new project in Android Studio, Add your project name and other details and also select Empty template for create the app.

Now you can find java files or pages on your Android Studio.

Step 2

  • First go to layout/activity_main.xml and add the following code bellow the layout and before the < / >  tag.
<WebView
      android:id="@+id/webView"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
   </WebView>
Step 3
  • Now goto MainActivity.java and add following code

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
   private WebView webView;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      WebView webView = (WebView)findViewById(R.id.webView);
      webView.setWebViewClient(new WebViewClient());
      webView.loadUrl("https://www.tophubz.com");
      WebSettings webSettings = webView.getSettings();
      webSettings.setJavaScriptEnabled(true);
   }
   public void onBackPressed(){
      if (webView.canGoBack()){
         webView.goBack();
    } else {
         super.onBackPressed();
      }
   }
}
Step 4
  • Now you have to add internet permission code in androidManifest.xml for work your app on internnet.

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

Now all done. Now run your android application with your android emulator. ( Click Run )

* This is simple way. And next lessons i will show you how to improve your webview app for super perfomance and how to add another features for your app.



Tophubz.com

Tophubz.com is an International Multi-platform Media and Entertainment website developed by ALL in ONE Team. Fun , Quiz , Quotes , Memes , News , Gossips , Events , Food , Gif , Photoraphy , Travel , Videos , Music , Sport , Game , Movie , TV Shoes , Gossips , News , Education , Life Style , and all the things what you want you can find here. And also you can use our SinduLanthaya Forum to learn, share ideas and chat with worldwide members.

We know all people love to be happy but sadness also come with us. on Tophubz.com we share every posts to help you to smile and get some fun. And also you can read and watch everything on Tophubz.com for free. Every day we update Tophubz.com . If you want to listen music or Download, You can use SinduLanthaya.com

Share posts on Tophubz.com with your friends!!