Why is Android WebView refusing user input?

前端 未结 16 1886
半阙折子戏
半阙折子戏 2020-11-28 08:12

I\'m developing an Android application that uses a WebView to display the login page for Facebook. The page loads beautifully, and I\'m able to select the username/password

16条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 08:44

    These are most have

    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setUseWideViewPort(true);
    webview.requestFocus(View.FOCUS_DOWN);
    

    and if still not working then use one alternative below

    Alternative 1

    webview.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                    case MotionEvent.ACTION_UP:                     
                        if (!v.hasFocus()) {
                            v.requestFocus();
                        }
                        break;
                }               
                return false;
            }
        });
    

    Alternative 2

    webview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_UP:
                    v.requestFocusFromTouch();  
                    break;
            }               
            return false;
        }
    
    });
    

提交回复
热议问题