Skip to content

Instantly share code, notes, and snippets.

@messenger63
Created December 18, 2014 10:32
Show Gist options
  • Save messenger63/c5b59f1d2340fdfe3d01 to your computer and use it in GitHub Desktop.
Save messenger63/c5b59f1d2340fdfe3d01 to your computer and use it in GitHub Desktop.
Move drawer to top (above ActionBar).
//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