图片透明到状态栏的方法
效果展示:
(布局只包含置顶的一张图片)
实现方法:
- 设置透明状态栏
- 设置ContentView的
setFitsSystemWindows
为true
- 设置ContentView的第一个子
View
的setFitsSystemWindows
为false
,意思为不为系统view留空间
代码:
//在setContentView之后调用
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
ViewGroup viewGroup = (ViewGroup) this.findViewById(Window.ID_ANDROID_CONTENT);
View childView = viewGroup.getChildAt(0);
if (null != childView) {
ViewCompat.setFitsSystemWindows(childView,false);
}