下面列出了android.app.Dialog#getCurrentFocus ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void hideSoftInput(Dialog dialog) {
View view = dialog.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) dialog.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
/**
* 隐藏软键盘
*/
public static void hide(Dialog dialog)
{
View view = dialog.getCurrentFocus();
if (view instanceof TextView)
{
InputMethodManager mInputMethodManager = (InputMethodManager) dialog.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
mInputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN);
}
}
/**
* Forced hidden keyboard
*
* @param dialog
*/
public static void hideDialogSoftKeyboard(Dialog dialog) {
if (null == dialog) {
throw new RuntimeException("参数错误");
}
View view = dialog.getCurrentFocus();
if (null != view) {
InputMethodManager inputMethodManager = (InputMethodManager) dialog.getContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
public static void hideSoftInput(Dialog dialog) {
View view = dialog.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) dialog.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}