EditText点击输入后,再点击旁边空白处时,该EditText仍然没有失去焦点。

解决方案:

    public static void hideKeyboardAndClearFocus(Context context, View view) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
        View temp = view.findFocus();
        if (temp != null) {
            temp.clearFocus();
        }
    }

    View rootView = findViewById(R.id.root_layout);
    rootView.setOnClickListener(view -> {
        hideKeyboardAndClearFocus(this, rootView);
    });