I'm trying to create an Android app using Kotlin for the first time and am trying to use different fragment layouts when the user clicks on navigation icons without having them overlap my bottom navigation bar. I've created a FrameLayout with the intention of putting the fragment layouts within it, but am unclear on how to write the code to do so.
This is the MainActivity.kt that I have that covers the Nav bar now:
private val onNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
when (item.itemId) {
R.id.navigation_home -> {
setContentView(R.layout.fragment_home)
return@OnNavigationItemSelectedListener true
}
R.id.navigation_favorites -> {
setContentView(R.layout.fragment_favorite)
return@OnNavigationItemSelectedListener true
}
R.id.navigation_calculator -> {
setContentView(R.layout.fragment_calculator)
return@OnNavigationItemSelectedListener true
}
}
false
}
And this is my frame layout:
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above= "@id/nav_view">
</FrameLayout>