Is there a way to disable the zoom feature on input fields in webview?

后端 未结 10 1408
南笙
南笙 2021-02-05 21:18

When a user clicks in an input field or textarea, the application zooms in. Is there a simple way to disable it?

Currently have the meta tag:

meta name=\         


        
10条回答
  •  醉话见心
    2021-02-05 21:28

    In WebViewClassic.java, displaySoftKeyboard zooms in and pans if the actual scale is less than the default scale. There is a field in the WebWiew.class mDefaultScale float the source code shows that when you display softkeyboard the mActualScale will change.

    So making sure that mActualScale is >= mDefaultScale should prevent the panning and rescaling. (Below is source code for WebView.java from the grepcode site -- which is no longer running.)

    private void  displaySoftKeyboard(boolean isTextView) {
         InputMethodManager imm = (InputMethodManager)
         getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            if (isTextView) {
                if (mWebTextView == null) return;
                imm.showSoftInput(mWebTextView, 0);
    
                if (mActualScale < mDefaultScale) {
    
                    // bring it back to the default scale so that user can enter
    
                    // text.
                    mInZoomOverview = false;
                    mZoomCenterX = mLastTouchX;
                    mZoomCenterY = mLastTouchY;
                    // do not change text wrap scale so that there is no reflow
                    setNewZoomScale(mDefaultScale, false, false);
                    adjustTextView(false);
                }
            }
    
            else { // used by plugins
                imm.showSoftInput(this, 0);
            }
    
        }
    

    Code from googleSource--WebViewClassic.java in frameworks/base/core/java/android/webkit/WebViewClassic.java (for JellyBean api 17) shows similar functionality:

    /**
     * Called in response to a message from webkit telling us that the soft
     * keyboard should be launched.
     */
    private void displaySoftKeyboard(boolean isTextView) {
        InputMethodManager imm = (InputMethodManager)
                mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
        // bring it back to the default level scale so that user can enter text
        boolean zoom = mZoomManager.getScale() < mZoomManager.getDefaultScale();
        if (zoom) {
            mZoomManager.setZoomCenter(mLastTouchX, mLastTouchY);
            mZoomManager.setZoomScale(mZoomManager.getDefaultScale(), false);
        }
        // Used by plugins and contentEditable.
        // Also used if the navigation cache is out of date, and
        // does not recognize that a textfield is in focus.  In that
        // case, use WebView as the targeted view.
        // see http://b/issue?id=2457459
        imm.showSoftInput(mWebView, 0);
    }
    

提交回复
热议问题