Skip to content Skip to sidebar Skip to footer

How To Setup Android Webview To Make It Work Identically Android Browser?

What are the settings to enable or disable in WebView to do this?

Solution 1:

If you want to use a webview with exactly the same features as the native android browser, you have to check MANY options and settings. A WebView is made to NOT use all of the browsers options and settings for better performance and for having more controll on what the users can and can not do while browsing. to figure out all the opportunities you should read through the api documentation here: http://developer.android.com/reference/android/webkit/WebView.html

For some further dealing and handling with the WebView class also here are some usefull sample codelines: http://pankajchunchun.wordpress.com/2013/01/09/example-of-webview-with-result-handler-and-connection-timeout-handler/

I hope this will help you.

Solution 2:

this is the webview example source..

what kind of setting do you wanna know??

publicclassMainActivityextendsActivity {
    WebView webview;
    @OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        webview = (WebView)findViewById(R.id.webview);
        webview.setWebViewClient(newWebClient()); 
        WebSettingsset= webview.getSettings();
        set.setJavaScriptEnabled(true);
        set.setBuiltInZoomControls(true);
        webview.loadUrl("http://www.google.com");

        findViewById(R.id.btnStart).setOnClickListener(onclick);
    }

    OnClickListeneronclick=newOnClickListener() {

        @OverridepublicvoidonClick(View v) {
            String url= null;
            EditTextadd= (EditText)findViewById(R.id.add);
            url = add.getText().toString();
            webview.loadUrl(url);           
        }
    };

    classWebClientextendsWebViewClient {
        publicbooleanshouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            returntrue;
        }
    }

Solution 3:

In addition to @Ssam's answer, you might want to manage the back button press so your app/Activity doesn't get closed on back press.

@OverridepublicvoidonBackPressed() {
        if (webview.canGoBack()) {
            webview.goBack();
        }elsesuper.onBackPressed();

    }

where webview is your webview

Post a Comment for "How To Setup Android Webview To Make It Work Identically Android Browser?"