¿Cómo deshabilitar el mensaje de sugerencia que aparece a veces con los controles de zoom en un WebView?

I haven't tested this on any other devices but on a 2.1 device, in a WebView with the zoom controls turned on, a toast message sometimes comes up that says something like "Tip: double tap to zoom in and out". I don't know where it is coming from as nothing in my code asked for it to appear. Is there any way to disable this?

I don't know how to reproduce it but it seems to happen more often when the app is freshly installed.

preguntado el 09 de enero de 11 a las 00:01

2 Respuestas

As indicated in wajiw's answer, the toast is based on the double tap toast count in WebSettings. There is a workaround based on preempting that value. WebSettings gets its value for double tap toast count from SharedPreferences. Overriding the preferences value will disable the toast.

The preferences are based on private values in WebSettings so it's not ideal. If the implementation changes, this could very well stop working. So, use at your own risk.

Here are the values WebSettings uses for the SharedPreferences. You'll need to duplicate them in your class.

private static final String PREF_FILE = "WebViewSettings";
private static final String DOUBLE_TAP_TOAST_COUNT = "double_tap_toast_count";

Then, you'll need to change the values before you use the WebView

SharedPreferences prefs = context.getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE);
if (prefs.getInt(DOUBLE_TAP_TOAST_COUNT, 1) > 0) {
    prefs.edit().putInt(DOUBLE_TAP_TOAST_COUNT, 0).commit();
}

Más info: WebSettings source code para más información.

Respondido 22 Jul 11, 13:07

From looking at the WebView.java source it's coming from the startDrag function:

private void startDrag() {
        WebViewCore.reducePriority();
        // to get better performance, pause updating the picture
        WebViewCore.pauseUpdatePicture(mWebViewCore);
        if (!mDragFromTextInput) {
            nativeHideCursor();
        }
        WebSettings settings = getSettings();
        if (settings.supportZoom()
                && settings.getBuiltInZoomControls()
                && !getZoomButtonsController().isVisible()
                && mMinZoomScale < mMaxZoomScale
                && (mHorizontalScrollBarMode != SCROLLBAR_ALWAYSOFF
                        || mVerticalScrollBarMode != SCROLLBAR_ALWAYSOFF)) {
            mZoomButtonsController.setVisible(true);
            int count = settings.getDoubleTapToastCount();
            if (mInZoomOverview && count > 0) {
                settings.setDoubleTapToastCount(--count);
                Toast.makeText(mContext,
                        com.android.internal.R.string.double_tap_toast,
                        Toast.LENGTH_LONG).show();
            }
        }
    }

the settings are accessible through getSettings(). From there I would try to call setDoubleTapToastCount and use something like 0 or -1 for the value. If that doesn't work you may be out of luck.

See full source of WebView.java Aquí

Respondido el 20 de enero de 11 a las 02:01

Based on the visibility of setDoubleTapToastCount and reviewing the source of WebSettings, it does not currently seem possible to disable this message. - Nick Campion

@nick that's what I came up with, but if someone wants to find out for sure they should create a test app and try out what they can. I feel like it's only going to lead to a dead end though - wajiw

I took a look around at the code and yea, it doesn't look possible. Too bad. Thanks for the find though. - cottonBallPaws

There is a bug report, but still no comment on a possible workaround :( code.google.com/p/android/issues/detail?id=18528 - NoBugs

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.