<xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <WebView android:id="@+id/webview_one" android:layout_width="match_parent" android:layout_height="match_parent"></WebView> </FrameLayout>package com.ducat.deep.tutorial; import android.app.ProgressDialog; import android.content.DialogInterface; import android.graphics.Bitmap; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.view.KeyEvent; import android.view.View; import android.webkit.WebResourceRequest; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.ProgressBar; import android.widget.Toast; import com.ducat.deep.tutorial.R; /** * Created by DEEP on 1/16/2018. */ public class WebDemo extends AppCompatActivity { WebView w; ProgressDialog pb; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.rel); w=findViewById(R.id.webview_one); pb=new ProgressDialog(this); pb.setTitle("Please Wait.."); w.loadUrl("https://www.google.com/"); WebSettings webSettings = w.getSettings(); webSettings.setJavaScriptEnabled(true); WebViewClient wc=new DeepWeb(); w.setWebViewClient(wc); } private class DeepWeb extends WebViewClient{ @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { pb.show(); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); pb.dismiss(); } } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && w.canGoBack()) { w.goBack(); return true; } else{ alertMessage(); return false; } } private void alertMessage(){ AlertDialog.Builder a=new AlertDialog.Builder(this); a.setTitle("Exit From Application"); a.setMessage("Do u want to close app ? "); a.setCancelable(false); a.setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); a.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); a.show(); } }
WebView in android example
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment