Created
November 22, 2014 13:19
-
-
Save LarsEliasNielsen/9f2d1f85ad2f07569bb6 to your computer and use it in GitHub Desktop.
Open navigation drawer when application opens
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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