由于在Activity的onCreate中設(shè)置了statusbar透明,并且讓布局可以延伸到statusbar區(qū)域,如下:
private void initStatusBar() {
// 設(shè)置status bar的顏色為透明,這個(gè)接口需要設(shè)置第3個(gè)參數(shù)(透明度)
StatusBarUtil.setColor(this, Color.TRANSPARENT, 0);
// 設(shè)置布局可以到status bar的區(qū)域
getWindow().getDecorView()
.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
}
這樣在根布局CoordinatorLayout和AppBarLayout中如果設(shè)置android:fitsSystemWindows="true"而且toolbar也設(shè)置了android:fitsSystemWindows="true"就會(huì)導(dǎo)致toolbar移出后還有一部分在statusbar位置顯示(如圖),沒有完全移出。所以只需要將toolbar設(shè)置一個(gè)android:fitsSystemWindows="true"就可以完全移出了。

沒有完全移出的toolbar.png