user868426
user868426

Reputation: 73

Always show zoom controls in WebView

Is there any way to always show zoom controls in webview? I found this: Always show zoom controls on a MapView but that's for the mapview. I want them to always be visible.

    super.onCreate(savedInstanceState);
    super.loadUrl("file:///android_asset/www/index.html");
    WebSettings ws = super.appView.getSettings();
    ws.setSupportZoom(true);
    ws.setBuiltInZoomControls(true);

Upvotes: 2

Views: 2844

Answers (3)

Brandon
Brandon

Reputation: 703

Not sure if this will work as I never tried, but I checked the reference in developer.android.com

ws.setDisplayZoomControls(true);

Also check this out: https://web.archive.org/web/20210127130931/http://www.tutorialforandroid.com/2009/02/webview-with-zoomcontrols-in-android.html

good tutorial. (Debunks my theory)

Upvotes: 0

CaptainCrunch
CaptainCrunch

Reputation: 1403

None of the above worked for my. Only when I start draging the webview content the controls show up the first time. So what I did as a "quick fix" is in onStart() of my Fragment that holds the Dialog with the webview I call:

webview.invokeZoomPicker();

Example:

    @Override
    public void onStart(){
        super.onStart();
        DialogFragment dialog = this;
       //...stuff
        if(dialog.getDialog()!= null && dialog.getDialog().getWindow()!=null){
            //...more stuff
            View v = dialog.getView();
            if(v!=null){
                //invoke controls on start once, they stay active a few seconds:
                WebView webview =v.findViewById(R.id.frag_dlg_WebView);
                webview.invokeZoomPicker();
            }
        }
    }

The controls light up only for a few seconds until they disappear again, by then the user in my case should have dragged the webview already.

Upvotes: 0

Robin Nixon
Robin Nixon

Reputation: 141

setDisplayZoomControls() is only available from API 11 (Android 3). So you can't even consider using it until the vast majority of Android devices are 3 or above - which will not be for some years :(

Upvotes: 1

Related Questions