键盘edittext时得到专注?
这个问题在这里已经有了答案:
通过InputMethodManager
您可以显示和隐藏软键盘。 使用toggleSoftInput()
方法在EditText
获取焦点时显示软键盘,并在EditText
失去焦点时使用hideSoftInputFromWindow()
隐藏键盘,如下所示...
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);
}
}
});
试用这些代码..
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
链接地址: http://www.djcxy.com/p/93379.html