Android软键盘操作常用工具类
其他
2018-06-07 05:07:20
阅读次数: 2
Android开发常用的软件盘操作工具:
实现功能:
1.软键盘打开与关闭
2.判断当前软键盘是否打开
/**
* 判断当前软键盘是否打开
*
* @param activity
* @return
*/
public static boolean isSoftInputShow(Activity activity) {
// 虚拟键盘隐藏 判断view是否为空
View view = activity.getWindow().peekDecorView();
if (view != null) {
// 隐藏虚拟键盘
InputMethodManager inputmanger = (InputMethodManager) activity
.getSystemService(Activity.INPUT_METHOD_SERVICE);
// inputmanger.hideSoftInputFromWindow(view.getWindowToken(),0);
return inputmanger.isActive() && activity.getWindow().getCurrentFocus() != null;
}
return false;
} |
/**
* 打开软键盘
*
* @param mEditText
* @param mContext
*/
public static void openKeybord(EditText mEditText, Context mContext) {
InputMethodManager imm = (InputMethodManager) mContext
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mEditText, InputMethodManager.RESULT_SHOWN);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
InputMethodManager.HIDE_IMPLICIT_ONLY);
} |
/**
* 关闭软键盘
*
* @param mEditText输入框
* @param mContext上下文
*/
public static void closeKeybord(EditText mEditText, Context mContext) {
InputMethodManager imm = (InputMethodManager) mContext
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
} |
转载自blog.csdn.net/u014133119/article/details/80579096