android中状态栏变透明的实现方法:
2021-07-05 本文已影响0人
写代码的向日葵
protected void setStatusBarTransparent() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
View decorView = getWindow().getDecorView();
decorView.setOnApplyWindowInsetsListener((v, insets) -> {
WindowInsets defaultInsets = v.onApplyWindowInsets(insets);
return defaultInsets.replaceSystemWindowInsets(
defaultInsets.getSystemWindowInsetLeft(),
0,
defaultInsets.getSystemWindowInsetRight(),
defaultInsets.getSystemWindowInsetBottom());
});
ViewCompat.requestApplyInsets(decorView);
getWindow().setStatusBarColor(ContextCompat.getColor(this, android.R.color.transparent));
}
}