如果系统4.4+,直接设置Activity的Window属性即可
JAVA对应的样式
if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
//状态栏透明
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//导航栏透明
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
XML对应的样式 :values-v19
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
备注:
如果使用了ActionBar,可能内容就跑到了状态栏了,此时可设置布局是否考虑状态栏,这样系统就会自动调整边距。
<item name="android:fitsSystemWindows">true</item>
也可以获取状态栏一般高度,也可以直接填充
获取方式:
//状态栏高度
int resourceId = Resources.getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = Resources.getDimensionPixelSize(resourceId);
}
//ActionBar高度
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
TypedValue tv = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
result = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
}
反正喜欢你就随便折腾呗
但是针对4.4一下肿么破,有人搞出来了,还了下还好,怎么使用还是看自己吧