From f55336983cbeeb0ec7c627ea24e2d311a9e0618f Mon Sep 17 00:00:00 2001 From: Ishan09811 <156402647+Ishan09811@users.noreply.github.com> Date: Fri, 2 Feb 2024 18:27:42 +0530 Subject: [PATCH] add smooth animation ``onNavigationItemSelected`` --- .../panda3ds/pandroid/app/MainActivity.java | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/MainActivity.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/MainActivity.java index 18914a804..53ceb1996 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/MainActivity.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/MainActivity.java @@ -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; - } -} \ No newline at end of file + // 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; + } + +}