Fix DrawerLayout in MainActivity has extra background color in immersive interface on Android 11.

This commit is contained in:
Alex Ning 2020-10-19 12:13:43 +08:00
parent 658af22c04
commit 1283ad62bb

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.Gravity; import android.view.Gravity;
@ -247,6 +248,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
} }
if (isImmersiveInterface()) { if (isImmersiveInterface()) {
drawer.setStatusBarBackgroundColor(Color.TRANSPARENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
drawer.setFitsSystemWindows(false); drawer.setFitsSystemWindows(false);
drawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | drawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
@ -266,6 +268,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
linearLayoutBottomAppBar.getPaddingTop(), 0, navBarHeight); linearLayoutBottomAppBar.getPaddingTop(), 0, navBarHeight);
navDrawerRecyclerView.setPadding(0, 0, 0, navBarHeight); navDrawerRecyclerView.setPadding(0, 0, 0, navBarHeight);
} }
} else {
drawer.setStatusBarBackgroundColor(mCustomThemeWrapper.getColorPrimaryDark());
} }
} }
@ -343,7 +347,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
protected void applyCustomTheme() { protected void applyCustomTheme() {
int backgroundColor = mCustomThemeWrapper.getBackgroundColor(); int backgroundColor = mCustomThemeWrapper.getBackgroundColor();
drawer.setBackgroundColor(backgroundColor); drawer.setBackgroundColor(backgroundColor);
drawer.setStatusBarBackgroundColor(mCustomThemeWrapper.getColorPrimaryDark());
int bottomAppBarIconColor = mCustomThemeWrapper.getBottomAppBarIconColor(); int bottomAppBarIconColor = mCustomThemeWrapper.getBottomAppBarIconColor();
option1BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); option1BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
option2BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); option2BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN);