How to remove cross fade animation of Navigation UI (Jetpack Navigation Components)?

Viewed 238

So i have setup Bottom Navigation View with Navigation UI. (Navigation Components) In the below code the i have a Bottom Navigation View and Fragment Container View.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/fragment_container_view"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@id/bottom_navigation_view"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/mobile_navigation" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation_view"
        style="@style/Widget.MaterialComponents.BottomNavigationView"
        android:layout_width="0dp"
        android:layout_height="@dimen/_48sdp"
        app:itemBackground="?android:windowBackground"
        app:itemIconTint="@drawable/navigation_selector"
        app:labelVisibilityMode="unlabeled"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_nav_menu" />

</androidx.constraintlayout.widget.ConstraintLayout>

Below is the java code for the above xml code

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding activityMainBinding;

    private NavController navController;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        activityMainBinding = ActivityMainBinding
                .inflate(getLayoutInflater());

        setContentView(activityMainBinding.getRoot());

        NavHostFragment navHostFragment =
                (NavHostFragment) getSupportFragmentManager()
                        .findFragmentById(R.id.fragment_container_view);


        if (navHostFragment != null) {

            navController = navHostFragment.getNavController();

            NavigationUI.setupWithNavController(
                    activityMainBinding.bottomNavigationView, navController
            );

        }

    }

}

So the problem i'm facing is to somehow remove the cross fade animation that occur when the fragment is changed from bottom navigation. It appear weird because i have custom toolbar in my each fragment layout.

0 Answers
Related