Created
March 5, 2021 07:42
-
-
Save widiarifki/55e240a86fb10066ddb5b8d229c56014 to your computer and use it in GitHub Desktop.
Jetpack Navigation with BottomNavigationView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Will be the UI entry point --> | |
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.coordinatorlayout.widget.CoordinatorLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<!-- FragmentContainerView --> | |
<androidx.fragment.app.FragmentContainerView | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_marginBottom="@dimen/bottomnav_height" | |
android:id="@+id/navHostFragment" | |
android:name="androidx.navigation.fragment.NavHostFragment" | |
app:defaultNavHost="true" | |
app:navGraph="@navigation/nav_graph" /> | |
<!-- BottomNavigationView --> | |
<com.google.android.material.bottomnavigation.BottomNavigationView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_gravity="bottom" | |
android:background="@android:color/white" | |
app:menu="@menu/bottomnav_menu" | |
app:itemIconSize="@dimen/_16sdp" | |
android:id="@+id/bottomMenu"/> | |
</androidx.coordinatorlayout.widget.CoordinatorLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Launcher activity **/ | |
package id.widiarifki.kitsu.presentation | |
import android.os.Bundle | |
import androidx.navigation.fragment.NavHostFragment | |
import androidx.navigation.ui.setupWithNavController | |
import com.google.android.material.bottomnavigation.BottomNavigationView | |
import dagger.hilt.android.AndroidEntryPoint | |
import id.widiarifki.kitsu.R | |
import id.widiarifki.kitsu.base.ui.activity.NonBindingActivity | |
class MainActivity : NonBindingActivity() { | |
override val resourceLayout: Int | |
get() = R.layout.activity_main | |
override fun onViewReady(savedInstanceState: Bundle?) { | |
setupBottomNavMenu() | |
} | |
private fun setupBottomNavMenu() { | |
val host = supportFragmentManager.findFragmentById(R.id.navHostFragment) as NavHostFragment? ?: return | |
val navController = host.navController | |
val bottomNav = findViewById<BottomNavigationView>(R.id.bottomMenu) | |
bottomNav.setupWithNavController(navController) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment