Mon application comporte deux onglets qui se collent au bas de l'écran. Ces onglets arrivent en haut de l'écran chaque fois qu'un des deux fragments attachés aux onglets est remplacé par un autre fragment.AppCompatActivity avec les onglets en bas pour accéder aux onglets en haut à chaque fois qu'un fragment est remplacé
Voici mon code qui remplace le fragment:
// Create fragment and give it an argument for the selected article
AudioPlayback newFragment = new AudioPlayback();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack so the user can navigate back
transaction.replace(R.id.container, newFragment);
transaction.addToBackStack(null);
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
// Commit the transaction
transaction.commit();
Et voici ma mise en page de conteneurs:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:padding="0dip"
android:gravity="center_horizontal"
android:id="@+id/container"
android:layout_width="match_parent" android:layout_height="match_parent">
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabIndicatorHeight="3px"
app:tabIndicatorColor="@android:color/holo_blue_dark"
app:tabGravity="fill" />
</LinearLayout>
je remplace le fragment en utilisant une interface qui soit mis en oeuvre dans l'activité principale. Ceci est fait correctement et avec succès.
Pouvez-vous donner des conseils sur la façon de garder les onglets au fond après le remplacement du fragment?
Je pense que votre conteneur n'est pas au bon endroit dans le format xml. Pourriez-vous s'il vous plaît partager le fichier de mise en page? –
Salut Arpit, J'ai édité ma question avec le code du conteneur ci-dessus. Fondamentalement, le conteneur est le LinearLayout qui intègre ViewPager et TabLayout. – Malloc