В моем приложении я загружаю ящик для навигации со следующим .xml. В первой группе у меня есть предмет для current_device
и other_device
. Существует возможность иметь несколько других устройств, перечисленных здесь, но это определяется во время выполнения с вызовом api. Есть ли способ динамически добавлять элементы в этот .xml? Или лучший способ сделать это. сЭлементы ящика навигации Runtime
<?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>
Навигационный макет ящика ниже:
<?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>
Проверьте мой ответ [http://stackoverflow.com/a/33072681/1050058](http://stackoverflow.com/a/33072681/1050058) –