<分区>
在我的 Activity 中有三个 editText View ,它会在某个时间随机隐藏
在 editText 中输入单个文本后,软键盘将自动消失
现在我想在 editText 获得焦点时显示软键盘
这该怎么做?
提前致谢
<分区>
在我的 Activity 中有三个 editText View ,它会在某个时间随机隐藏
在 editText 中输入单个文本后,软键盘将自动消失
现在我想在 editText 获得焦点时显示软键盘
这该怎么做?
提前致谢
最佳答案
通过 InputMethodManager
您可以显示和隐藏软键盘。使用 toggleSoftInput()
EditText
时显示软键盘的方法获得焦点并使用 hideSoftInputFromWindow()
在 EditText
时隐藏键盘失去焦点如下...
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean isFocused) {
if (isFocused) {
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
} else {
imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
}
}
});
关于android - 如何在编辑文本获得焦点时显示软键盘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22402446/