class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val bottomNavigationView = findViewById<BottomNavigationView>(R.id.bottomNavigationView)
val navController = findNavController(R.id.fragmentContainerView)
// val appBarConfiguration = AppBarConfiguration(setOf(R.id.a1, R.id.a2, R.id.a3))
// setupActionBarWithNavController(navController, appBarConfiguration)
bottomNavigationView.setupWithNavController(navController)
}
}
<?xml version="1.0" encoding="utf-8"?>
<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">
<fragment
android:id="@+id/fragmentContainerView"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/my_nav"
android:layout_marginBottom="60dp" />
<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:menu="@menu/bottom_menu"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/a1"
android:title="1"
android:icon="@drawable/ic_launcher_foreground"
/>
<item
android:id="@+id/a2"
android:title="2"
android:icon="@drawable/ic_launcher_foreground"
/>
<item
android:id="@+id/a3"
android:title="3"
android:icon="@drawable/ic_launcher_foreground"
/>
</menu>
'Android(Kotlin)' 카테고리의 다른 글
Android ROOM sqlcipher (0) | 2022.09.20 |
---|---|
Android AlarmManager (0) | 2022.09.16 |
ViewModelFactory 오류 (0) | 2022.08.19 |
bumblebee 이상 firebase import (0) | 2022.08.12 |
Android BindingAdapter (0) | 2022.07.31 |