mirror of
https://github.com/Skysamara/android-kotlin-fundamentals-apps.git
synced 2025-12-06 06:16:03 +00:00
Android Kotlin Fundamentals 03.2: Define navigation paths
10. Task: Add the navigation drawer Step 4: Display the navigation drawer
This commit is contained in:
parent
8c386416cf
commit
bdf620331e
@ -59,4 +59,6 @@ dependencies {
|
|||||||
|
|
||||||
implementation"android.arch.navigation:navigation-fragment-ktx:$navigationVersion"
|
implementation"android.arch.navigation:navigation-fragment-ktx:$navigationVersion"
|
||||||
implementation "android.arch.navigation:navigation-ui-ktx:$navigationVersion"
|
implementation "android.arch.navigation:navigation-ui-ktx:$navigationVersion"
|
||||||
|
|
||||||
|
implementation "com.google.android.material:material:$supportlibVersion"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
val navController = this.findNavController(R.id.myNavHostFragment)
|
val navController = this.findNavController(R.id.myNavHostFragment)
|
||||||
NavigationUI.setupActionBarWithNavController(this, navController)
|
NavigationUI.setupActionBarWithNavController(this, navController)
|
||||||
|
NavigationUI.setupWithNavController(binding.navView, navController)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSupportNavigateUp(): Boolean {
|
override fun onSupportNavigateUp(): Boolean {
|
||||||
|
|||||||
@ -16,6 +16,10 @@
|
|||||||
|
|
||||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<androidx.drawerlayout.widget.DrawerLayout
|
||||||
|
android:id="@+id/drawerLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -32,4 +36,13 @@
|
|||||||
/>
|
/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.navigation.NavigationView
|
||||||
|
android:id="@+id/navView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="start"
|
||||||
|
app:headerLayout="@layout/nav_header"
|
||||||
|
app:menu="@menu/navdrawer_menu" />
|
||||||
|
</androidx.drawerlayout.widget.DrawerLayout>
|
||||||
|
|
||||||
</layout>
|
</layout>
|
||||||
|
|||||||
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/rulesFragment"
|
||||||
|
android:icon="@drawable/rules"
|
||||||
|
android:title="@string/rules" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/aboutFragment"
|
||||||
|
android:icon="@drawable/about_android_trivia"
|
||||||
|
android:title="@string/about" />
|
||||||
|
</menu>
|
||||||
@ -57,4 +57,9 @@
|
|||||||
android:name="com.example.android.navigation.AboutFragment"
|
android:name="com.example.android.navigation.AboutFragment"
|
||||||
android:label="fragment_about"
|
android:label="fragment_about"
|
||||||
tools:layout="@layout/fragment_about" />
|
tools:layout="@layout/fragment_about" />
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/rulesFragment"
|
||||||
|
android:name="com.example.android.navigation.RulesFragment"
|
||||||
|
android:label="fragment_rules"
|
||||||
|
tools:layout="@layout/fragment_rules" />
|
||||||
</navigation>
|
</navigation>
|
||||||
Loading…
x
Reference in New Issue
Block a user