Search code examples
androidandroid-activityandroid-tabsandroid-actionbar-compat

How to display fragment *over* tabulation setup as Play Store Settings does?


My application has 3 main screens (1 fragment for each) presented in an Action Bar Compat with NAVIGATION_MODE_TABS.

From the action bar and the menu, the user will be able to reach for

  • settings,
  • profile,
  • credit card
  • etc.

Which are less used functionality. So I feel (from android guidelines) that they should not be regrouped inside a 4th tabulation (as they are currently).

How to display the less-used fragments with a similar feeling to the way Google Play creates and displays its screen Settings (leaving the tabs mode)? Do I need a secondary activity? Can I stay in the same activity (best case for me) and how?


Solution

  • Create a second Activity, where you can show your other fragments. You can put a flag in the Intent, which you need for the startActivity() method, so you can check which fragment should be shown in your OtherActivity. For the up navigation you need to edit your manifest like this, to set activity hirarchy:

     <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/MyTheme" >
            <activity
                android:name="com.test.ActivityMain"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:name="com.test.OtherActivity"
                android:parentActivityName="com.test.ActivityMain" >
            <!-- Parent activity meta-data to support API level 7+ -->
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.test.ActivityMain" />
            </activity>
        </application>
    

    You also have to add this line code to the onCreate() method in your OtherActivity to see the up navigation button:

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    

    Otherwise can stay in your activity, replace your fragment and hide() the Actionbar, but the hide() animation looks a little bit strange. Besides you won't have a up button and it's not the best practice.