Daryn
Daryn

Reputation: 768

Android Webview: Disable zoom on input

I want to disable zoom when clicking on input. I read many posts but couldn't find real solution. Any idea?

There is my code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    progress = findViewById(R.id.progress);
    webView = (WebView) findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
    webView.getSettings().setRenderPriority(RenderPriority.HIGH);
    webView.getSettings().setPluginState(android.webkit.WebSettings.PluginState.ON_DEMAND);
    webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    webView.setWebViewClient(new Z_MyWebViewClient());
    webView.getSettings().setDisplayZoomControls(false);
    webView.getSettings().setSupportZoom(false);
    webView.getSettings().setDefaultZoom(ZoomDensity.FAR);
    webView.loadUrl(BASE_URL);
}

Upvotes: 2

Views: 3062

Answers (1)

Matt
Matt

Reputation: 728

Add the following line to the head section of your HTML page to disable zoom when tapping on a text input field:

<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>

As per the official Android Developer documentation, this is the preferred solution, the WebSettings.setDefaultZoom() method you are calling was deprecated in API 19.

Upvotes: 3

Related Questions