c# - 从底部滑动出现导航栏时如何隐藏BottomNavigationView?
问题描述
当从屏幕底部边缘滑动并出现系统导航栏时,我想隐藏 BottomNavigationView。现在系统导航栏是半透明的,并且悬停在 BottomNavigationView 上方。
活动 XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start"
android:fitsSystemWindows="false">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="@layout/include_toolbar"/>
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/appbar"/>
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:background="@color/app_background"
app:itemIconTint="@color/main_text_color"
app:labelVisibilityMode="unlabeled"
android:paddingHorizontal="@dimen/normal_margin"
app:elevation="2dp"
app:menu="@menu/bottom_navigation_main"
android:layout_gravity="bottom"/>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
片段 OnResume():
public override void OnResume()
{
base.OnResume();
if (ParentActivity.BottomNavigation != null)
ParentActivity.BottomNavigation.Visibility = ViewStates.Visible;
View decorview = ParentActivity.Window.DecorView;
var uiOptions =
SystemUiFlags.HideNavigation |
SystemUiFlags.ImmersiveSticky;
decorview.SystemUiVisibility = (StatusBarVisibility)uiOptions;
}
片段实现 View.IOnSystemUiVisibilityChangeListener
public void OnSystemUiVisibilityChange([GeneratedEnum] StatusBarVisibility visibility)
{
if (((int)visibility & (int)SystemUiFlags.Fullscreen) == 0)
{
if (ParentActivity.BottomNavigation != null)
ParentActivity.BottomNavigation.Visibility = ViewStates.Gone;
}
else
{
if (ParentActivity.BottomNavigation != null)
ParentActivity.BottomNavigation.Visibility = ViewStates.Visible;
}
}
侦听器不会对导航栏的外观做出反应。
滑动后导航栏出现时不调用 OnSystemUiVisibilityChange()
解决方案
你需要OnSystemUiVisibilityChangeListener
- https://developer.android.com/reference/android/view/View.OnSystemUiVisibilityChangeListener
例如,在您的活动中onCreate()
:
window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
// Note that system bars will only be "visible" if none of the
// LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
if (visibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0) {
// TODO: The system bars are visible. Make any desired
// adjustments to your UI, such as showing the action bar or
// other navigational controls.
} else {
// TODO: The system bars are NOT visible. Make any desired
// adjustments to your UI, such as hiding the action bar or
// other navigational controls.
}
}
然后,您可以使底部导航视图的可见性与系统 UI 保持同步。
推荐阅读
- go - Go 中的竞争条件变化
- android - 包含 androidx 库函数的 Unity 插件
- angularjs - angularjs将html编辑器数据限制在一定范围内
- c++ - 在新范围内使用 unique_lock 是否等同于在共享资源工作结束时解锁调用?
- matlab - 在给出绘图误差的值范围内绘制传递函数没有足够的输入参数
- reactjs - React-Native 无法调用函数
- python - 无法从块中挖出特定部分的文本
- html - Bootstrap 导航问题:无法更改不同列的背景颜色
- angular - 当我尝试在生产模式下构建我的 angular-6 捆绑包时出现错误“找不到模块”?
- php - 未找到“PDO”类 - 已安装 PDO 驱动程序