Skip to content Skip to sidebar Skip to footer

Can I Use A Compatible Action Bar And A Fragment In The Same Activity?

OK, I've been extending my activities to extends ActionBarActivity My main menu page extends FragmentActivity when I change it to extend ActionBarActivity so I can see my actio

Solution 1:

ActionBarActivity extends android.support.v4.app.FragmentActivity, so ActionBarActivity serves both purposes.

Solution 2:

Is your code from the Action Bar compatibility example that comes with the SDK? If so just change the ActionBarActivity class in that example to extend FragmentActivity (from the compatibility library I assume) instead of Activity.

Solution 3:

Experienced same problem and the solution, as mentioned in other responses, is to edit your ActionBarActivity class.

This class is defined in your code (com.google.android.actionbarcompat). The only thing you have to do is change extends Activity to extends FragmentActivity from the android.support.v4.app.FragmentActivity.

Solution 4:

Do you have menu items for your Fragments? Use your own app namespace instead of android for app:showAsAction and app:actionLayout, etc.

To add your namespace to the XML use this line in the menu tag

xmlns:app="http://schemas.android.com/apk/res-auto"

E.g.

<menuxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"><itemandroid:id="@+id/menu_settings"app:showAsAction="ifRoom"android:title="@string/menu_settings"android:orderInCategory="100" /></menu>

Note the app:showAsAction rather than android:showAsAction

Post a Comment for "Can I Use A Compatible Action Bar And A Fragment In The Same Activity?"