Fragment replaced still visible on background

后端 未结 3 956
一整个雨季
一整个雨季 2020-12-28 18:59

I\'m trying to replace one fragment with another one using new navigation drawer pattern. It seems to work but when I choose another option from drawer the new fragment is l

相关标签:
3条回答
  • 2020-12-28 19:38

    I have same issue with some fragments. To solve it I simple set background color for all fragment layouts, for example:

    android:background="?android:attr/colorBackground"
    
    0 讨论(0)
  • 2020-12-28 19:45

    I tried a lot of suggested answers here on SO and after expending hours I finally could solve my problem without having to specify a background color on my fragment's layout.

    My solution is to override the onBackPressed method on the Activity holding the fragment container, so every time the back button is pressed I will remove the current shown fragment and bring back the previous one:

    @Override
    public void onBackPressed() {
        List<Fragment> fragments = getSupportFragmentManager().getFragments();
        if (fragments.size() > 1) {
    
            final Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.my_framelayout);
            if (currentFragment != null) {
                getSupportFragmentManager().beginTransaction().remove(currentFragment).commit();
                getSupportFragmentManager().popBackStack();
            }
        } else {
            super.onBackPressed();
        }
    }
    

    Hope this helps.

    0 讨论(0)
  • 2020-12-28 19:59

    Try to change the android:background="@android:color/background_light" color to some other color.May be this solves your problem.

    0 讨论(0)
提交回复
热议问题