public static void hiddenKeyboard(Context context,ViewGroup root){ final int childCount = root.getChildCount(); for (int i = 0; i < childCount; ++i) { final View child = root.getChildAt(i); if(child instanceof EditText){ InputMethodManager imm = (InputMethodManager)context.getSystemService( context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(child.getWindowToken(), 0); } if (child instanceof ViewGroup) { hiddenKeyboard(context,(ViewGroup) child); } } }
这是自己封装好的方法