问题明确显示了编辑文本。 再见,我在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);
}
});
答案 0 :(得分:0)
最后,我找到了答案,只需要在布局xml文件中添加这两行。就我而言,我将它们放在父级布局中,就可以解决问题
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"