2

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);
}
5
  • when input is activated turn off the zoom
    – Amy
    Commented Dec 19, 2014 at 4:38
  • Thank you, have you got an example code?
    – Daryn
    Commented Dec 19, 2014 at 5:11
  • You mean edit text in webview or in android view?
    – Amy
    Commented Dec 19, 2014 at 5:15
  • no, I mean about input component in HTML loading by my WebView
    – Daryn
    Commented Dec 19, 2014 at 5:18
  • No I think its seems not possible
    – Amy
    Commented Dec 19, 2014 at 5:19

1 Answer 1

3

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.