In my app I'm loading the navigation drawer with the following .xml. In the first group I have an item for current_device
and other_device
. There is potential to have several other devices listed here, but this is determined at runtime with an api call. Is there a way to dynamically add items to this .xml? Or a better way to do this. c
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group
android:id="@+id/nav_devices_group"
android:checkableBehavior="single">
<item
android:id="@+id/nav_current_device"
android:icon="@drawable/common_full_open_on_phone"
android:title="@string/nav_current_device" />
<item
android:id="@+id/nav_other_device"
android:icon="@drawable/common_full_open_on_phone"
android:title="@string/nav_devices" />
</group>
<group>
<item
android:id="@+id/nav_settings"
android:icon="@drawable/ic_setting_dark"
android:title="@string/nav_settings" />
<item
android:id="@+id/nav_about"
android:icon="@android:drawable/ic_dialog_info"
android:title="@string/nav_about" />
</group>
</menu>
The nav drawer layout is below:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/menu_nav_drawer" />
</android.support.v4.widget.DrawerLayout>