您的位置:首页 > 其它

透明状态栏

2015-06-30 13:22 211 查看
private boolean isLmpOrAbove() {

return Build.VERSION.SDK_INT >= 21;//Build.VERSION_CODES.LOLLIPOP;

}

//状态栏透明

@TargetApi(19)

private void setupTransparentSystemBarsForLmp() {

// TODO(sansid): use the APIs directly when compiling against L sdk.

// Currently we use reflection to access the flags and the API to set

// the transparency

// on the System bars.

if (isLmpOrAbove()) {

try {

getWindow().getAttributes().systemUiVisibility |= (View.SYSTEM_UI_FLAG_LAYOUT_STABLE

| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField("FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");

getWindow().addFlags(drawsSysBackgroundsField.getInt(null));

Method setStatusBarColorMethod = Window.class.getDeclaredMethod("setStatusBarColor", int.class);

Method setNavigationBarColorMethod = Window.class.getDeclaredMethod("setNavigationBarColor", int.class);

setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);

setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);

} catch (NoSuchFieldException e) {

Log.w("yfl", "NoSuchFieldException while setting up transparent bars");

} catch (NoSuchMethodException ex) {

Log.w("yfl", "NoSuchMethodException while setting up transparent bars");

} catch (IllegalAccessException e) {

Log.w("yfl", "IllegalAccessException while setting up transparent bars");

} catch (IllegalArgumentException e) {

Log.w("yfl", "IllegalArgumentException while setting up transparent bars");

} catch (InvocationTargetException e) {

Log.w("yfl", "InvocationTargetException while setting up transparent bars");

} finally {

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: