1

I do have a simple requirement. I want new android Navigation Drawer to open upon start of Activity.

I have tried

mDrawerLayout.openDrawer(drawerListView);

in onCreate of host activity. But it didn't work.

Any kind of help would be appreciated. Thank you.

kaushal trivedi
  • 3,405
  • 3
  • 29
  • 47

2 Answers2

2

try to move the code to onResume() and set a flag that the action is done so it won't happen every time activity goes foreground

Maxim Efimov
  • 2,747
  • 1
  • 19
  • 25
  • @kaushaltrivedi because in `onCreate` views are not displayed yet, so all of them have 0dp in all dimentions(is you measure it, you will see) and thus can't be `opened` – Maxim Efimov Sep 14 '13 at 05:19
  • Well i wrote the code at end of onCreate after getting references of each object and assigning memory to each component.I dont know but do you really think that view completes it rendering just before onResume and thats why it didnt work when i wrote it at end of onCreate. – kaushal trivedi Sep 15 '13 at 03:05
  • @kaushaltrivedi yes, I do. You can verify it by getting some view width and height - it probably will be 0dp even in the end of `onCreate` – Maxim Efimov Sep 17 '13 at 02:20
0

put this line

mDrawerLayout.openDrawer(drawerListView);

at the end of onCreate it workes fine.