How to focus on Webview upon selecting an EditText within same Layout in Android?

后端 未结 1 1821
广开言路
广开言路 2021-01-15 04:41

I have been trying to add EditTexts and WebView in a layout. The trouble is with focussing on WebView. I have tried to look through the answers on the web and Stackoverflow

相关标签:
1条回答
  • 2021-01-15 05:08

    I encountered the same problem a few weeks ago. The answer is simple, set an onTouchListener to the webview and then set it up as follows:

    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;
    }
    

    Edit: Infact I found an exact duplicate in the "Related" category, read this.

    Let me know if its not what you're looking for.

    0 讨论(0)
提交回复
热议问题