Note the adjusting the insets is a specific workaround for views that do not respect layout settings. View Pager has such problems.
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setStatusBarTransparent() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
getWindow().setStatusBarColor(Color.TRANSPARENT);
// adjust insets to fix status bar transparency issue
ViewGroup v = (ViewGroup) findViewById(R.id.root);
v.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
return insets.consumeSystemWindowInsets();
}
});
}