Change focus of edittext when click outsite edittext

I have edit text to enter a url and a webview to display a website

My problem: when I go google.com I click on my edit text, so my edit text has focus.

I touched the search area in gooogle, but my edittext did not lose focus.

How can I change the focus of the edittext if you click outsite edittext?

+3
source share
2 answers

Get the answer from here: EditText, clear focus when tapping out

and here:

Android: force click EditText to remove focus?

You can make the cursor and focus disappear on

edittext.clearFocus();
+3
source

Do something on the line

/**
 * 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;
}
-2
source

All Articles