删除片段后如何清除焦点?

how to clearfocus after remove a fragment?

从应用中删除片段后,编辑文本的清晰焦点出现问题。 再见,我在 android 9 中没有任何问题,但我的真实设备有 android 7,问题出现在那里

   searchFab.setOnClickListener(v -> {
            Fragment fragment = new SearchFragment();
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            transaction.setCustomAnimations(R.anim.fragment_bottom_up, R.anim.fragment_top_down
                    , R.anim.fragment_bottom_up, R.anim.fragment_top_down);
            transaction.replace(R.id.fragment_area, fragment);
            transaction.addToBackStack(null);
            if (searchEditText.isFocused()) {
                if (searchEditText.getText().toString().equals("")) {
                    inputMethodManager.hideSoftInputFromWindow(searchEditText.getWindowToken(), 0);
                    searchEditText.clearFocus();
                    searchFabIcon.startAnimation(animationHide);
                    searchFabIcon.setImageResource(R.drawable.ic_search);
                    searchFabIcon.startAnimation(animationShow);
                    getSupportFragmentManager().popBackStack();
                } else {
                    searchEditText.setText("");
                }
            } else {
                transaction.commit();
                searchEditText.requestFocus();
                searchFabIcon.startAnimation(animationHide);
                searchFabIcon.setImageResource(R.drawable.ic_multiply);
                searchFabIcon.startAnimation(animationShow);
                inputMethodManager.showSoftInput(searchEditText,
InputMethodManager.SHOW_IMPLICIT);
            }
        });

终于找到答案了,只需要在你的layout xml文件中加入这两行即可。在我的例子中,我将它们放在父布局中并解决了问题

android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"