Android Navigation Library - Advanced
Pada post ini merupakan lanjutan dari post sebelumnya tentang navigation basic.jadi yang ini merupakan versi advanced dari yang sebelumnya, dimana bentuk aplikasinya lumayan kompleks. contohnya seperti berikut ini, halaman utama terdapat tiga fragment dengan bottom navigation view. dan ada detail untuk masing-masing menu (misal ada list notifikasi dengan detail notifikasi). lebih lengkapnya navigasinya seperti berikut. atau bisa dilihat di github readme repo post ini.
pastikan memahami tentang navigation basic dahulu. karena disini juga terdapat contoh arguments jika mengirim data antar fragment dengan parcelable.
yang perlu diperhatikan disini adalah penamaan id pada xml menu dan xml navigation graph harus sama untuk menu bottom navigation view. misal berikut contoh menu.xml
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
<?xml version="1.0" encoding="utf-8"?> | |
<menu xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:id="@+id/fragmentHome" | |
android:icon="@drawable/icon_home" | |
android:title="@string/menu_home"/> | |
<item android:id="@+id/fragmentDashboard" | |
android:icon="@drawable/icon_airport" | |
android:title="@string/menu_dashboard"/> | |
<item android:id="@+id/fragmentNotification" | |
android:icon="@drawable/icon_notification" | |
android:title="@string/menu_notification"/> | |
</menu> |
dan berikut contoh navigation.xml
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
<?xml version="1.0" encoding="utf-8"?> | |
<navigation 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:id="@+id/nav_graph" | |
app:startDestination="@id/fragmentHome"> | |
<!-- fragment home --> | |
<fragment | |
android:id="@+id/fragmentHome" | |
android:label="@string/fragment_home" | |
android:name="com.yoesuv.navigationadvanced.HomeFragment" | |
tools:layout="@layout/fragment_home"> | |
</fragment> | |
<!-- fragment dashboard --> | |
<fragment | |
android:id="@+id/fragmentDashboard" | |
android:label="@string/fragment_dashboard" | |
android:name="com.yoesuv.navigationadvanced.DashboardFragment" | |
tools:layout="@layout/fragment_dashboard"> | |
<action android:id="@+id/action_dashboard_to_dashboard_detail" | |
app:destination="@id/fragmentDashboardDetail"/> | |
</fragment> | |
<!-- fragment dashboard detail --> | |
<fragment | |
android:id="@+id/fragmentDashboardDetail" | |
android:label="@string/fragment_dashboard_detail" | |
android:name="com.yoesuv.navigationadvanced.DashboardDetailFragment" | |
tools:layout="@layout/fragment_dashboard_detail"> | |
</fragment> | |
<!-- fragment notification --> | |
<fragment | |
android:id="@+id/fragmentNotification" | |
android:label="@string/fragment_notification" | |
android:name="com.yoesuv.navigationadvanced.NotificationFragment" | |
tools:layout="@layout/fragment_notification"> | |
<action android:id="@+id/action_notification_to_notification_detail" | |
app:destination="@id/fragmentNotificationDetail"/> | |
</fragment> | |
<!-- fragment notification detail --> | |
<fragment | |
android:id="@+id/fragmentNotificationDetail" | |
android:label="@string/fragment_notification_detail" | |
android:name="com.yoesuv.navigationadvanced.NotificationDetailFragment" | |
tools:layout="@layout/fragment_notification_detail"> | |
<argument | |
android:name="data_detail_notification" | |
app:argType="com.yoesuv.navigationadvanced.SampleDataModel" | |
app:nullable="true" | |
android:defaultValue="@null"/> | |
</fragment> | |
</navigation> |
mohon maaf jika tidak menulis secara lengkap untuk post kali ini.
langsung cek repository githubnya disini.
selamat mencoba.
Langganan:
Posting Komentar
(
Atom
)
Tidak ada komentar :
Posting Komentar