Kenny
Kenny

Reputation: 815

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?

Upvotes: 0

Views: 445

Answers (2)

Kenny
Kenny

Reputation: 815

After reading over Android documentation, something that worked fine in ActionBarShelock and in 4.x does NOT work in 2.x with ActionBarCompat, but isn't explicitly documented.

If an activity is created WITHOUT a setContentView() and a fragment added via

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

That fragment will be cover the ActionBar in 2.2 (and possibly other Android versions). Using an explicit setContentView with a simple layout and adding the the fragment to that layout, works across all Android versions...

Upvotes: 0

blackcj
blackcj

Reputation: 3661

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

Upvotes: 1

Related Questions