Android 点击outsite edittext时更改edittext的焦点
我有一个编辑文本来输入url,还有一个webview来显示网站 我的问题是:当我去google.com时,我点击我的编辑文本,这样我的编辑文本就有了焦点 我在谷歌中点击搜索区域,但我的编辑文本并没有失去焦点Android 点击outsite edittext时更改edittext的焦点,android,focus,android-edittext,Android,Focus,Android Edittext,我有一个编辑文本来输入url,还有一个webview来显示网站 我的问题是:当我去google.com时,我点击我的编辑文本,这样我的编辑文本就有了焦点 我在谷歌中点击搜索区域,但我的编辑文本并没有失去焦点 点击outsite edittext时,如何更改edittext的焦点?在 /** * hide soft keyboard */ private void hideSoftKeyboard() { InputMethodManager inputManager = (Input
点击outsite edittext时,如何更改edittext的焦点?在
/**
* 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;
}
从这里得到答案:
在这里:
您可以通过以下方式使光标和焦点消失:
edittext.clearFocus();
此答案仅隐藏键盘,但不会更改编辑文本框的焦点。