当我EditText
失去焦点时,我正在尝试关闭键盘。我为此使用此代码
edt.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
InputMethodManager imm = (InputMethodManager) getBaseContext().getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
Log.d(TAG, "edt focus lost");
}
if (hasFocus)
Log.d(TAG, "edt has focus");
}
});
当我触摸它时,我立即获得焦点。但是直到离开屏幕我才不会失去专注。
我尝试打开Dialogs
页面上的其他对象,Views
用自己的听众触摸其他对象,但是在离开屏幕之前不会触发“焦点丢失”消息。
为什么会这样呢?
可聚焦视图(例如this EditText
)仅在另一个可聚焦视图获得焦点时才会失去焦点。默认情况下,大多数视图无法聚焦。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句