android 设置状态栏全透明,背景延伸到状态栏

//最终方案
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {    
    //5.0 全透明实现
    //getWindow.setStatusBarColor(Color.TRANSPARENT)
    Window window = getWindow();
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |                 View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);    
    window.setStatusBarColor(Color.TRANSPARENT);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {    
 //4.4 全透明状态栏
     getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}   

然后在界面布局(layout)的xml里面的根view上设置上 fitsSystemWindows="true"

详情请见:

https://www.jianshu.com/p/7dcfd243b1df

展开阅读全文

没有更多推荐了,返回首页