How to create android app for website.?How to open website in android app

activity_main.xml

Just add webView to xml


Main Activity.Java

 import android.os.Bundle;  
 import android.support.annotation.Nullable;  
 import android.support.v7.app.AppCompatActivity;  
 import android.webkit.WebView;  
 import android.webkit.WebViewClient;  
 public class MainActivity extends AppCompatActivity {  
   private WebView mywebView;  
   String url="www.google.com";  
   @Override  
   protected void onCreate(@Nullable Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.activity_main);  
     mywebView=findViewById(R.id.web);  
     mywebView.getSettings().setJavaScriptEnabled(true);  
     mywebView.getSettings().setSupportZoom(true);  
     mywebView.getSettings().setUseWideViewPort(true);  
     mywebView.getSettings().setLoadWithOverviewMode(true);  
     mywebView.loadUrl(url);  
     mywebView.setWebViewClient(new WebViewClient());  
   }  
   @Override  
   public void onBackPressed() {  
     if(mywebView.canGoBack()) {  
       mywebView.goBack();  
     } else {  
       super.onBackPressed();  
     }  
   }  
 }  


No comments:

Post a Comment