How to show Toolbar's logo, icon, title, subtitle when wrapped in a CollapsingToolbarLayout?

断了今生、忘了曾经 提交于 2019-11-30 07:29:26

This issue was reported here as a bug. I have personally experienced this with one of my apps. Setting the topMargin for the toolbar works for me. As somebody commented on the bug report, here is the fix, as a function from the issue report.

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);
}

See the result here.

Ran into the same issue. For me it was fixed by removing the android:fitsSystemWindows="true" from the layoutparameters. However, this will mean that the status bar will not be part of the collapsing Toolbar backdrop.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!