自定义底部导航视图

重要

本文介绍的功能和指南为公共预览版,在正式发布之前可能会有重大修改。 Microsoft 不对此处提供的信息作任何明示或默示的担保。

BottomNavigationViewBottomNavigationView,可检测折叠功能,并在其左侧或右侧安置其子视图。

displayPosition - 确定在哪个屏幕上呈现视图。 可以是以下三个值之一:

  • DisplayPosition.START - 在折叠功能左侧归组。 START: tabs on the first screen

  • DisplayPosition.END - 在折叠功能右侧归组。 END: tabs on the first screen

  • DisplayPosition.DUAL - 跨整个屏幕(可能出现在铰链下方)。 DUAL: tabs on the first screen

bottomNavigationView.displayPosition = DisplayPosition.START

可以使用 app:display_position 属性来实现同样的效果:

<com.microsoft.device.dualscreen.bottomnavigation.BottomNavigationView
    android:id="@+id/nav_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:menu="@menu/bottom_nav_menu"
    tool:tools_application_mode="dual_screen"
    .....
    app:display_position="start"
     />

arrangeButtons - 当应用程序跨过了折叠功能而组件有奇数个按钮时,铰链将覆盖中间的按钮(如果设备具有物理铰链)。 避免这种情况的一种方法是,在每个屏幕上以不同方式排列按钮:

The buttons can be arranged in different ways on the two screens

bottomNavigationView.arrangeButtons(3, 2)

useTransparentBackground - 当应用程序跨过整个屏幕宽度,并且组件的一部分不包含任何按钮时,该部分的屏幕背景可能变为透明:

The background on the first screen is transparent

bottomNavigationView.useTransparentBackground = true

useAnimation - 确定按钮排列改变时是否使用动画。 默认情况下,将使用 AccelerateDecelerateInterpolator。 利用 animationInterpolator 属性,可以将它更改为其他任何插值器。

bottomNavigationView.useAnimation = true
bottomNavigationView.animationInterpolator = OvershootInterpolator()

allowFlingGesture - 如果设置为 true,可在组件上使用快速滑动手势将 displayPosition 设置为 DisplayPosition.START 或 DisplayPosition.END。

bottomNavigationView.allowFlingGesture = true