最近开发新app,参考其他app,发现好多有状态栏一体化 ,就是背景图片能显示在状态栏的。
让状态栏占位消失,在想要实现这个效果的activity中调用这方法就行。
@TargetApi(19) private void setTranslucentStatus(boolean on) { Window win = getWindow(); WindowManager.LayoutParams winParams = win.getAttributes(); final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if (on) { winParams.flags |= bits; } else { winParams.flags &= ~bits; } win.setAttributes(winParams); }
然后因为状态栏占位消失了 ,下面的布局会往上移,所以要使自己的布局多一个状态栏高度margintop的位置。
public int getStatusBarHeight() { int result = 0; int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { result = getResources().getDimensionPixelSize(resourceId); } return result; }这是计算状态栏位置的方法。