0

I can customize android navigations actions easily, like this code, but I am not able to customize actions coming from drawer or bottomnavigation and menu.

Is there a way to customize this actions? Actions coming from this configurantion setupActionBarWithNavController?

        <action
            android:id="@+id/action_flow_step_two_dest_to_notificationsFragment"
            app:destination="@id/notificationsFragment"
            app:enterAnim="@anim/navigation_slide_in_right"
            app:exitAnim="@anim/navigation_slide_out_left"
            app:popEnterAnim="@anim/navigation_slide_in_left"
            app:popExitAnim="@anim/navigation_slide_out_right" />

1 Answers1

0

Looking at the source code, I notice that the navigation library replace every animation passed with a default one when menu navigation happen.

public static boolean onNavDestinationSelected(@NonNull MenuItem item,
        @NonNull NavController navController) {
    NavOptions.Builder builder = new NavOptions.Builder()
            .setLaunchSingleTop(true)
            .setEnterAnim(R.anim.nav_default_enter_anim)
            .setExitAnim(R.anim.nav_default_exit_anim)
            .setPopEnterAnim(R.anim.nav_default_pop_enter_anim)
            .setPopExitAnim(R.anim.nav_default_pop_exit_anim);
    if ((item.getOrder() & Menu.CATEGORY_SECONDARY) == 0) {
        builder.setPopUpTo(findStartDestination(navController.getGraph()).getId(), false);
    }
    NavOptions options = builder.build();
    try {
        //TODO provide proper API instead of using Exceptions as Control-Flow.
        navController.navigate(item.getItemId(), null, options);
        return true;
    } catch (IllegalArgumentException e) {
        return false;
    }
}

You can't change the animation as you wish, but you can replace the default ones, you need to use the following names in your anim files.

nav_default_enter_anim

nav_default_exit_anim

nav_default_pop_enter_anim

nav_default_pop_exit_anim