Issue
I am using Navigation component, and I have a bottom navigation view in the main activity. when I tap the tab in that bottom navigation view, it seems that there is a fade in animation when the fragment appear. I don't think I manually set the animation, it seems that the animation will be there by default.
I want to remove that animation. here is the code I use in my Main Activity.
class MainActivity : AppCompatActivity(), NavController.OnDestinationChangedListener {
private lateinit var navController : NavController
lateinit var destinationTitleTextView : TextView
lateinit var progressBar : ProgressBar
lateinit var topToolbar : Toolbar
lateinit var bottomNavigationView : BottomNavigationView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
FirebaseApp.initializeApp(this)
// Initial Setup views
navController = Navigation.findNavController(this,R.id.nav_host_fragment)
setupBottomNavMenu(navController)
setupActionBar(navController)
setUpViewDeclaration()
// Add Listeners
navController.addOnDestinationChangedListener(this)
}
private fun setUpViewDeclaration() {
destinationTitleTextView = findViewById(R.id.destination_label_text_view)
progressBar = findViewById(R.id.progressBar_main_activity)
topToolbar = findViewById(R.id.top_toolbar)
bottomNavigationView = findViewById(R.id.bottom_nav)
}
private fun setupBottomNavMenu(navController: NavController) {
bottom_nav.setupWithNavController(navController)
}
private fun setupActionBar(navController: NavController) {
setSupportActionBar(top_toolbar)
supportActionBar?.setDisplayShowTitleEnabled(false)
// set up top hierarchy destination
val appBarConfiguration = AppBarConfiguration(setOf(
R.id.destination_home,
R.id.destination_search,
R.id.destination_user_control,
R.id.destination_create_event)
)
top_toolbar.setupWithNavController(navController,appBarConfiguration)
}
}
Solution
UPDATE: The latest file path please see comment below.
You can add anim file to replace the default animation.
- res/anim/nav_default_enter_anim.xml
- res/anim/nav_default_exit_anim.xml
- res/anim/nav_default_pop_enter_anim.xml
- res/anim/nav_default_pop_exit_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!--Empty to disable animation-->
</set>
[Navigation Component] I can`t change animation from NavigationUI.setupWithNavController()
Answered By - Kiwi Lin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.