android – Modify the activity_main_drawer.xml from an external server xml


I have this activity_main_drawer.xml file inside res/menu/ folder

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="">
    <group android:checkableBehavior="single">
            android:title="@string/inicio" />

What I am trying to do is modify it, based on an xml that I get from an external server. Or instead of modifying it, use the external xml , instead of this for the android side menu


The server xml is like this:

<?xml version="1.0" encoding="utf-8"?>
        <nombre idZona="1">Home</nombre>
        <nombre idZona="2">Pantalla 1</nombre>
        <nombre idZona="3">Pantalla 2</nombre>
        <nombre idZona="4">Pantalla 3</nombre>

And I read it through Parser SAX


If I'm wrong, you can change the elements of the Navigation Drawer in the OnCreate() method of your Activity . At first I can think of several options:

Option 1 : change the menu to another that exists in the resources. Example:

 navigationView.getMenu().clear(); //Borrar los elementos anteriores.

Option 2 : change the menu by adding menu items by hand using the menu's own functions add () and addSubMenu () . Example:

 Menu menu = navigationView.getMenu();
 for (int i = 1; i <= 3; i++) {
     menu.add("Menu "+ i);

 SubMenu subMenu = menu.addSubMenu("SubMenu");
 for (int i = 1; i <= 2; i++) {
     subMenu.add("SubMenu " + i);
Scroll to Top