Code example for WebView

Methods: getSettingssetWebViewClient, setOnKeyListener

0
 
        if (mWebView != null) {
            mWebView.destroy();
        } 
         
        mWebView = new WebView(getActivity());
        mWebView.setOnKeyListener(new OnKeyListener(){
 
            @Override 
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                  if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
                        mWebView.goBack();
                        return true; 
                    } 
                    return false; 
            } 
 
        }); 
        mWebView.setWebViewClient(new InnerWebViewClient()); // forces it to open in app
        mWebView.loadUrl(mUrl);
        mIsWebViewAvailable = true;
        WebSettings settings = mWebView.getSettings();
        settings.setJavaScriptEnabled(true);
        return mWebView;
    } 
 
    /** 
Contextual code suggestions in your IDE  Get Codota for Java