【问题标题】:how to clearfocus after remove a fragment?删除片段后如何清除焦点?
【发布时间】:2019-04-07 05:28:27
【问题描述】:

从应用程序中删除片段后编辑文本的清晰焦点问题。 顺便说一句,我在 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);
            }
        });

【问题讨论】:

    标签: android fragment android-fragmentactivity android-lifecycle


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多