Skip to content

Instantly share code, notes, and snippets.

@JohnMars
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save JohnMars/4de6ae4d95044b05843d to your computer and use it in GitHub Desktop.

Select an option

Save JohnMars/4de6ae4d95044b05843d to your computer and use it in GitHub Desktop.
Fixing bug that puts toolbar out of screen on API 21
private void fixApi21ToolBarBug(Toolbar toolbar){
if(Build.VERSION.SDK_INT!=21) return; //only on api 21
final int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
final int result = (resourceId>0) ? getResources().getDimensionPixelSize(resourceId)*2 : 0;
final CollapsingToolbarLayout.LayoutParams params =
(CollapsingToolbarLayout.LayoutParams)toolbar.getLayoutParams();
params.topMargin -= result;
toolbar.setLayoutParams(params);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment