Skip to content

Instantly share code, notes, and snippets.

@LarsEliasNielsen
Created November 22, 2014 13:19
Show Gist options
  • Save LarsEliasNielsen/9f2d1f85ad2f07569bb6 to your computer and use it in GitHub Desktop.
Save LarsEliasNielsen/9f2d1f85ad2f07569bb6 to your computer and use it in GitHub Desktop.
Open navigation drawer when application opens
public class MainActivity extends Activity {
// Delay in millisec.
private static final int DRAWER_DELAY = 200;
// Member varaible for navigation drawer.
private DrawerLayout mNavigationDrawerLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
// Get the navigation drawer and assign to member variable.
mNavigationDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
// Set handler with delay.
new Handler().postDelayed(openDrawerRunnable(), DRAWER_DELAY);
}
// Threaded method for opening navigation drawer.
private Runnable openDrawerRunnable() {
return new Runnable() {
@Override
public void run() {
mNavigationDrawerLayout.openDrawer(Gravity.LEFT);
// or
// mNavigationDrawerLayout.openDrawer(Gravity.START);
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment