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
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"
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.
Try to change the android:background="@android:color/background_light" color to some other color.May be this solves your problem.