2

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);
Community
  • 1
  • 1
user868426
  • 63
  • 2
  • 5

3 Answers3

1

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 :(

Robin Nixon
  • 141
  • 1
0

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.

CaptainCrunch
  • 1,230
  • 14
  • 15
0

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)

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Brandon
  • 693
  • 1
  • 9
  • 23
  • Not working! It says that ws doesn't have function setDisplayZoomControls. – user868426 Jul 28 '11 at 23:32
  • .setDisplayZoomControls(Boolean enabled) is a standard method for WebSettings so that doesn't make much sense. Try replacing it instead of .setBuiltInZoomControls. – Brandon Jul 28 '11 at 23:36
  • look at the link i edited into the answer. That should get it working – Brandon Jul 28 '11 at 23:37
  • I was on that link earlier. A lot of errors. And replacing is not working. – user868426 Jul 28 '11 at 23:40
  • try this: final View zoom = super.appView.getZoomControls(); zoom.setVisibility(View.VISIBLE); – Brandon Jul 28 '11 at 23:55
  • if you have to add a framelayout or relativelayout then add the zoom into the layout (framelayouts and relativelayouts allow views to overlay each other) – Brandon Jul 28 '11 at 23:56
  • With this final View zoom = super.appView.getZoomControls(); zoom.setVisibility(View.VISIBLE); the app won't start. – user868426 Jul 29 '11 at 10:23
  • what does the ddms say? Plus super.appView might not be correct, I am just guessing that is your webview based off the code you gave – Brandon Jul 29 '11 at 22:50