can I use a compatible action bar AND a fragment in the same activity?

后端 未结 4 1899
-上瘾入骨i
-上瘾入骨i 2021-02-07 04:30

OK, I\'ve been extending my activities to

extends ActionBarActivity

My main menu page

extends FragmentActivity
相关标签:
4条回答
  • 2021-02-07 04:46

    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.

    0 讨论(0)
  • 2021-02-07 04:53

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

    0 讨论(0)
  • 2021-02-07 04:55

    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.

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

    Note the app:showAsAction rather than android:showAsAction

    0 讨论(0)
  • 2021-02-07 05:04

    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.

    0 讨论(0)
提交回复
热议问题