6

Is it possible to create and add to app Navigation Drawer without using xml?
Every example i saw had an additional xml file with layout.
Nowadays i try to initialize this with:

DrawerLayout sidePanel = new DrawerLayout(this);

and then add this sidePanel using View method addView() but it cause exception.
Is it possible to add Navigation Drawer using only java code?

4
  • Does the navigation drawer not live in it's own fragment? I cannot see the advantage of this Commented Apr 25, 2014 at 9:12
  • 2
    OP, why would you not use an XML? What's the problem with adding an XML if it is how it works for everybody? Commented Apr 25, 2014 at 9:26
  • 1
    In fact i just wonder is it possible at all. Generaly i tought i can add everything stright from code (and until today it was true), but this one is some kind of exception from rule or i don't know how to do it properly. Commented Apr 25, 2014 at 9:35
  • @shkschneider not all app using xml for example the game (because it usually only contain 1 view / openGLView), and i also need to implement drawer in my game Commented Jul 11, 2019 at 2:51

1 Answer 1

-1

yes , you can do that without the XML, but still you would require a layout to at least hold that navigation drawer that you need

Sign up to request clarification or add additional context in comments.

3 Comments

Can you give me some example? As i understand drawer contains some layout not inversely.
you need to create XML with Frame layout that will contain the fragments of your navigation drawer. an exemplary layout I have added above
This answer would be improved if you said how you achieve this. Simply saying yes isn't particularly helpful. Also you should avoid answering the same question twice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.