Измените заполнение внизу, проводя пальцем по временной навигационной панели

#android #kotlin #android-navigation-bar

Вопрос:

В макете моего полноэкранного приложения у меня есть типичный BottomNavigationView , который мешает временной нижней панели навигации, когда я провожу пальцем вверх, чтобы открыть ее.

У меня есть такой макет:

 lt;?xml version="1.0" encoding="utf-8"?gt; lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:app="http://schemas.android.com/apk/res-auto"  android:id="@ id/container"  android:layout_width="match_parent"  android:layout_height="match_parent"gt;   lt;androidx.appcompat.widget.Toolbar  android:id="@ id/toolbar"  android:layout_width="match_parent"  android:layout_height="?attr/actionBarSize"  android:background="?android:attr/windowBackground"  android:elevation="0dp"  android:theme="@style/ThemeOverlay.AppCompat.ActionBar"  app:popupTheme="@style/Theme.MyApp.PopupOverlay"  app:layout_constraintLeft_toLeftOf="parent"  app:layout_constraintRight_toRightOf="parent"  app:layout_constraintTop_toTopOf="parent" /gt;   lt;androidx.fragment.app.FragmentContainerView  android:id="@ id/nav_host_fragment_activity_main"  android:name="androidx.navigation.fragment.NavHostFragment"  android:layout_width="match_parent"  android:layout_height="match_parent"  app:defaultNavHost="true"  app:layout_constraintLeft_toLeftOf="parent"  app:layout_constraintRight_toRightOf="parent"  app:layout_constraintTop_toTopOf="parent"  app:navGraph="@navigation/mobile_navigation" /gt;   lt;com.google.android.material.bottomnavigation.BottomNavigationView  android:id="@ id/nav_view"  android:layout_width="0dp"  android:layout_height="wrap_content"  android:layout_marginStart="0dp"  android:layout_marginEnd="0dp"  android:background="?android:attr/windowBackground"  android:elevation="0dp"  app:layout_constraintBottom_toBottomOf="parent"  app:layout_constraintLeft_toLeftOf="parent"  app:layout_constraintRight_toRightOf="parent"  app:menu="@menu/bottom_nav_menu"  app:labelVisibilityMode="unlabeled" /gt;  lt;/androidx.constraintlayout.widget.ConstraintLayoutgt;  

В своей деятельности я пытаюсь интерактивно скрыть панель навигации

 class MainActivity : AppCompatActivity() {  private lateinit var binding: ActivityMainBinding   override fun onCreate(savedInstanceState: Bundle?) {  super.onCreate(savedInstanceState)   binding = ActivityMainBinding.inflate(layoutInflater)  setContentView(binding.root)   setSupportActionBar(findViewById(R.id.toolbar))   val navView: BottomNavigationView = binding.navView   val navHostFragment = supportFragmentManager.findFragmentById(  R.id.nav_host_fragment_activity_main  ) as NavHostFragment  val navController = navHostFragment.navController   val appBarConfiguration = AppBarConfiguration(  setOf(  R.id.navigation_activitati, R.id.navigation_proiecte, R.id.navigation_necesitati,  R.id.navigation_inventar, R.id.navigation_organizare  )  )   setupActionBarWithNavController(navController, appBarConfiguration)  navView.setupWithNavController(navController)   // this is where I handle the insets  ViewCompat.setOnApplyWindowInsetsListener(binding.root) { view, windowInsets -gt;  val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())  if (view.layoutParams is MarginLayoutParams) {  val p = view.layoutParams as MarginLayoutParams  p.setMargins(insets.left, insets.top, insets.right, 0)  view.requestLayout()  }  WindowInsetsCompat.CONSUMED  }  }   override fun onWindowFocusChanged(hasFocus: Boolean) {  super.onWindowFocusChanged(hasFocus)  if (hasFocus) hideSystemUI()  }   // this is where the bars are hidden  private fun hideSystemUI() {  WindowCompat.setDecorFitsSystemWindows(window, false)   WindowInsetsControllerCompat(window, binding.root).let { controller -gt;  val behavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE  controller.hide(WindowInsetsCompat.Type.navigationBars())  controller.systemBarsBehavior = behavior  }  } }  

All works fine, the system’s navigation bar is hidden and the BottomNavigationView is right at the bottom.

But I don’t like that when I swipe up to reveal the navigation bar it overlaps the BottomNavigationView . I would like the bottom padding to change accordingly so that the BottomNavigationView sits on top of the system’s navigation bar (or to get hidden when the bar is displayed)

Is this possible? I have tried many things and Android’s developer docs are outdated and useless, though they seem to address the issue