Search code examples
androiddynamicandroid-fragmentsandroid-actionbar-compat

ActionBarCompat and dynamic fragments


Is there an issue with creating dynamic fragments with the ActionBarCompat support library?

I have an application that I am converting from using ActionBarSherlock (v4.4 if it matters), to using the ActionBarCompat support library. It has worked with all Android versions from 2.2 upward without issues. After converting to using the ActionBarCompat support, and doing allowing for all the differences from ActionBarSherlock to the new support library I still have ONE remaining issue.

My application runs wonderfully using 4.x devices and emulators, BUT when I run it on devices and emulators running 2.2 (haven't tried 2.3 yet), any Activity that I create thats uses the following pattern to add a fragment to it, the fragment takes up the ENTIRE screen and the action bar isn't visible, but it is there (returns non-null from getSupportActionBar()).

    getSupportFragmentManager()
            .beginTransaction()
            .add(android.R.id.content, frag)
            .commit();

All fragments created using the setContent in layouts work just fine.

Thoughts?


Solution

  • Create your own container instead of using android.R.id.content. Android 2.3.3 adds the ActionBar to the root view element where 4+ is adding it outside of the root view.

    ActionBar Tabs with support library