Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the position of Toolbar while android verison >= 21 #12

Closed
wants to merge 1 commit into from

Conversation

seasonyuu
Copy link

when the android version is Lollipop(or higher),the position of Toolbar in CheeseDetailActivity would be out of the screen....fix this

@@ -42,6 +43,17 @@ public void onCreate(Bundle savedInstanceState) {
final String cheeseName = intent.getStringExtra(EXTRA_NAME);

final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if(Build.VERSION.SDK_INT>=21){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to Build.VERSION.SDK_INT == 21 as this issue is only present at that API level.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steffandroid I have no other device to test , my mistake

@chrisbanes chrisbanes closed this Jun 8, 2015
@rnascimento13
Copy link

this worked for me

//bug that puts toolbar out of screen
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
Labels
None yet
Projects
None yet
4 participants