'How to scroll-to-top by tap the bottom navigation icon?
Hello guys I use templater Bottom Navigation Activity and dont know how to scroll to top RecyclerView in my Home Fragment
My MainActivity code:
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(navView, navController);
Solution 1:[1]
The question is quit old, but maybe it helps others. This is the code you have to put in the fragment (in Kotlin):
val nav = activity?.findViewById<BottomNavigationView>(R.id.bottom_navigation)
nav?.setOnItemReselectedListener { item ->
if (item.itemId == R.id.mainFragment) {
recyclerView.smoothScrollToPosition(position)
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jannis |
