从应用程序中删除片段后编辑文本的清晰焦点问题。再见,我在 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);
}
});
最后我找到了答案,只需要在您的布局xml文件中添加这两行。 就我而言,我将它们放在父布局中,它解决了问题
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"