当我离开屏幕的EditText失去只专注 [英] EditText lose focus only when I leave the screen
问题描述
我试图关闭键盘时,的EditText
的焦点已丢失。而我用这个code为
I am trying to close the keyboard when the focus of EditText
has been lost. And I use this code for that
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");
}
});
当我触摸它,我立即得到关注的焦点。但我直到我离开屏幕不失去焦点。
When I touch it, I immediately get the focus. But I don't lose focus until I leave the screen.
我试过在页面上打开其它对话框
,触及其他查看
用自己的听众,而是聚焦丢失在我离开之前屏幕信息不被解雇。
I tried opening other Dialogs
on the page, touching other Views
with their own listeners, but "focus lost" message is not fired before I leave the screen.
为什么会出现这种情况?
Why is this happening?
推荐答案
一个可聚焦视图(如本的EditText
)只有失去焦点,当其他的可聚焦查看获得它。大多数意见都默认不聚焦的。
A focusable view (such as this EditText
) only loses focus when another focusable view gains it. Most views are not focusable by default.
这篇关于当我离开屏幕的EditText失去只专注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!