Hey,
I needed to create a Menu XML programmatically for a library. After a lot of research about it, i got almost nothing useful but actually it is hilariously easy to create dynamically.
Firstly we need to create a Menu object :
Menu menu = new MenuBuilder(getApplicationContext());
Then we can create as many item as we need by :
menu.add(0, Menu.FIRST, Menu.NONE, R.string.itemName).setIcon(R.drawable.itemDrawable);menu.add(1, Menu.FIRST + 1, Menu.NONE, R.string.itemName2).setIcon(R.drawable.itemDrawable2);
It is extremely simple and easy to use.
If you have any question, ask me :)