CoordinatorLayout status bar padding disappears from ViewPager 2nd page

后端 未结 4 1418
春和景丽
春和景丽 2020-12-24 07:00

EDIT of 01/02/2016: Bug should be resolved by applying the code provided by Android Team: https://stackoverflow.com/a/35132144/3397345, see accepted answer

4条回答
  •  忘掉有多难
    2020-12-24 07:40

    I ran into a similar issue (using v23.0.1). In my case, the problem occurs on the first page as well. The workaround I settled on was to adjust the padding and height of the toolbar when the fragment is created.

        // in onCreateView: adjust toolbar padding
        Toolbar toolbar = (Toolbar) mRootView.findViewById(R.id.toolbar);
        toolbar.setPadding(0, getStatusBarHeight(), 0, 0);
        toolbar.getLayoutParams().height = toolbar.getLayoutParams().height + getStatusBarHeight();
    
        return mRootView;
    }
    
    public int getStatusBarHeight() {
        int result = 0;
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }
    

提交回复
热议问题