Created
December 18, 2014 10:32
-
-
Save messenger63/c5b59f1d2340fdfe3d01 to your computer and use it in GitHub Desktop.
Move drawer to top (above ActionBar).
This file contains 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
//call in onCreate() | |
private void moveDrawerToTop() { | |
DrawerLayout drawer = (DrawerLayout) layoutInflater.inflate(R.layout.left_drawer, null); // "null" is important. | |
// HACK: "steal" the first child of left_drawer view | |
ViewGroup decor = (ViewGroup) getWindow().getDecorView(); | |
View child = decor.getChildAt(0); | |
decor.removeView(child); | |
LinearLayout container = (LinearLayout) drawer.findViewById(R.id.drawer_content); // This is the container we defined just now. | |
container.addView(child, 0); | |
drawer.findViewById(R.id.left_drawer).setPadding(0, getStatusBarHeight(), 0, 0); | |
// Make the drawer replace the first child | |
decor.addView(drawer); | |
} | |
public int getStatusBarHeight() { | |
int result = 0; | |
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); | |
if (resourceId > 0) { | |
result = getResources().getDimensionPixelSize(resourceId); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment