ActionBar List Moving Overlays

I try to implement the Android action bar in the list navigation mode, it successfully modifies fragments when an item is selected from the list, but the fragments overlap, and I see the contents of the previous one, which is still displayed on the screen when the second one is selected. Here is my code for Activity OnCreate and OnNavigationItemSelected:

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mFirstFragment = new FirstFragment(); mSecondFragment = new SecondFragment(); SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource( this, R.array.action_list, android.R.layout.simple_spinner_dropdown_item); mActionBar = getActionBar(); mActionBar.setDisplayShowTitleEnabled(false); mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); mActionBar.setListNavigationCallbacks(mSpinnerAdapter, this); if(savedInstanceState != null) { mActionBar.setSelectedNavigationItem( savedInstanceState.getInt("currFragment")); } } public boolean onNavigationItemSelected(int position, long itemId) { FragmentTransaction mFragmentTransaction = getFragmentManager().beginTransaction(); switch(position) { case FIRST_FRAGMENT: mFragmentTransaction.replace( android.R.id.content, mFirstFragment); break; case SECOND_FRAGMENT: mFragmentTransaction.replace( android.R.id.content, mSecondFragment); break; } mFragmentTransaction.commit(); return true; } 

Thanks in advance!

+7
source share
1 answer

I had the same problem. The accepted answer in FragmentTransaction.attach and .detach for Actionbar tabs worked for me. You can also get good pointers from the β€œAndroid Action Bar” tab, where scrollview made a duplicate view after changing orientation (although the key ideas that worked for me came from the first question I have related to).

+1
source

All Articles