Skip to content

Commit

Permalink
add smooth animation onNavigationItemSelected
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishan09811 authored Feb 2, 2024
1 parent fefe86e commit f553369
Showing 1 changed file with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,28 @@ protected void onCreate(Bundle savedInstanceState) {
}

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
FragmentManager manager = getSupportFragmentManager();
Fragment fragment;
if (id == R.id.games) {
fragment = gamesFragment;
} else if (id == R.id.search) {
fragment = searchFragment;
} else if (id == R.id.settings) {
fragment = settingsFragment;
} else {
return false;
}
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
FragmentManager manager = getSupportFragmentManager();
Fragment fragment;
if (id == R.id.games) {
fragment = gamesFragment;
} else if (id == R.id.search) {
fragment = searchFragment;
} else if (id == R.id.settings) {
fragment = settingsFragment;
} else {
return false;
}

manager.beginTransaction().replace(R.id.fragment_container, fragment).commitNow();
return true;
}
}
// Begin a FragmentTransaction and set custom animations for entering and exiting fragments.
FragmentTransaction transaction = manager.beginTransaction();
transaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);

// Replace the current fragment with the selected one.
transaction.replace(R.id.fragment_container, fragment).commit();

return true;
}

}

0 comments on commit f553369

Please sign in to comment.