4

I have a edit text to input url, and a webview to display the website

My problem is: when i go google.com, i tap to my edit text so my edit text has focus.

I tap to search area in gooogle, but my edittext doen't lose focus.

How can can i change focus of edittext when tap outsite edittext?

Nam Vu
  • 5,669
  • 7
  • 58
  • 90

2 Answers2

3

Get the answer from here: EditText, clear focus on touch outside

and here:

Android: Force EditText to remove focus?

You can make cursor and focus disappear by

edittext.clearFocus();
Community
  • 1
  • 1
Nam Vu
  • 5,669
  • 7
  • 58
  • 90
-2

Do something on the line of

/**
 * hide soft keyboard
 */
private void hideSoftKeyboard() {
    InputMethodManager inputManager = (InputMethodManager) getBaseContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputManager != null)
        inputManager.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);       
}

@Override
public boolean onTouch(View view, MotionEvent event) {
    if(view == mWebView) {
        hideSoftKeyboard();
    }
    return false;
}
mkso
  • 3,178
  • 4
  • 27
  • 35