Is there a better way to include a bottom nav on all the pages of my android application without having to copy this code to each of my activities? I think inheritance can be used but I am not too sure how to inherit and use a navigation class in Kotlin.
For my layout files, I include them currently by doing this:
<include
android:id="@+id/include"
layout="@layout/bottom_app_bar"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp" />
The implementation code that I need to include in all my Activity files:
var bottomNavigationView = findViewById<NavigationBarView>(R.id.bottomNavigationView)
bottomNavigationView.setOnItemSelectedListener {
when (it.itemId) {
R.id.miHome -> {
val navIntent = Intent(this, MainActivity::class.java)
startActivity(navIntent)
true
}
R.id.miAccount -> {
val navIntent = Intent(this, AccountActivity::class.java)
startActivity(navIntent)
true
}
else -> false
}
}