在Android中使用导航组件时如何删除默认动画过渡? [英] how to remove default animation transition when using navigation component in Android?

查看:498
本文介绍了在Android中使用导航组件时如何删除默认动画过渡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用导航组件,并且在主要活动中有一个底部导航视图.当我点击该底部导航视图中的选项卡时,出现该片段时,似乎动画中出现了淡入淡出的感觉.我不认为我会手动设置动画,似乎默认情况下动画会在那里.

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)

    }


}

推荐答案

根据此问题:

NavigationUI是一组遵循材料设计准则的助手,其中包括BottomNavigationView项之间的动画.

NavigationUI is a set of helpers which follow the material design guidelines and that includes animations between BottomNavigationView items.

您会在材料设计指南"的过渡"部分中进行记录,他们特别声明:

And you'll note in the Transitions section of the Material design guidelines, they specifically state:

使用淡入淡出动画在活动和不活动的底部导航目标之间进行转换.

Transition between active and inactive bottom navigation destinations using a cross-fade animation.

因此,导航不提供任何用于自定义或删除动画的API.

Therefore Navigation does not provide any API for customizing or removing the animations.

请注意,导航2.1.0-alpha03版本确实有此更改:

Note that the Navigation 2.1.0-alpha03 release did have this change:

NavigationUI提供的默认动画已从400ms加速到220ms,以匹配活动和片段的默认动画速度. b/130055522

因此,我建议1)升级到Navigation 2.1.0-alpha03或更高版本以获取更新的动画,以及2)遵循材料设计准则.

So I'd suggest 1) upgrading to Navigation 2.1.0-alpha03 or higher to get the updated animations and 2) following the material design guidelines.

当然,NavigationUI是完全可选的,您当然可以使用

Of course, NavigationUI is totally optional and you can certainly do whatever you want using the underlying OnDestinationChangedListener that NavigationUI uses under the hood.

这篇关于在Android中使用导航组件时如何删除默认动画过渡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆