I have an app in which I hide the navigation bar and show a bottom navigation. If I hide the former, the navigation should be at the bottom edge. how can I achieve this?
My layout file for the navigation:
<androidx.constraintlayout.widget.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_nav"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Code for hiding:
currentApiVersion = Build.VERSION.SDK_INT
val flags: Int = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
if (currentApiVersion >= Build.VERSION_CODES.KITKAT) {
window.decorView.systemUiVisibility = flags
val decorView: View = window.decorView
decorView.setOnSystemUiVisibilityChangeListener { visibility ->
if (visibility and View.SYSTEM_UI_FLAG_FULLSCREEN === 0) {
decorView.systemUiVisibility = flags
}
}
}
2
Answers
The code is from one of my older projects but i think it will still work. In your activitiy use below code:
try calling his function, in onCreate()