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 {
}
}
}
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 {
}
}
}