Modify the activity_main_drawer.xml from an external server xml


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

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

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


The server's 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 by Parser SAX

asked by Joacer 29.05.2017 в 14:00

1 answer


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

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

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

- Option 2 : change the menu by manually adding the menu items using the functions of the menu 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);
answered by 29.05.2017 / 15:39