mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add missing window flags for styling system bars (flutter/engine#32167)
This commit is contained in:
parent
6b600225ac
commit
15bb1b5e86
@ -363,6 +363,7 @@ public class PlatformPlugin {
|
||||
updateSystemUiOverlays();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void setSystemChromeSystemUIOverlayStyle(
|
||||
PlatformChannel.SystemChromeStyle systemChromeStyle) {
|
||||
Window window = activity.getWindow();
|
||||
@ -370,6 +371,20 @@ public class PlatformPlugin {
|
||||
WindowInsetsControllerCompat windowInsetsControllerCompat =
|
||||
new WindowInsetsControllerCompat(window, view);
|
||||
|
||||
if (Build.VERSION.SDK_INT < 30) {
|
||||
// Flag set to specify that this window is responsible for drawing the background for the
|
||||
// system bars. Must be set for all operations on API < 30 excluding enforcing system
|
||||
// bar contrasts. Deprecated in API 30.
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
|
||||
// Flag set to dismiss any requests for translucent system bars to be provided in lieu of what
|
||||
// is specified by systemChromeStyle. Must be set for all operations on API < 30 operations
|
||||
// excluding enforcing system bar contrasts. Deprecated in API 30.
|
||||
window.clearFlags(
|
||||
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
|
||||
| WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
|
||||
}
|
||||
|
||||
// SYSTEM STATUS BAR -------------------------------------------------------------------
|
||||
// You can't change the color of the system status bar until SDK 21, and you can't change the
|
||||
// color of the status icons until SDK 23. We only allow both starting at 23 to ensure buttons
|
||||
@ -433,8 +448,6 @@ public class PlatformPlugin {
|
||||
}
|
||||
// You can't change the color of the navigation bar divider color until SDK 28.
|
||||
if (systemChromeStyle.systemNavigationBarDividerColor != null && Build.VERSION.SDK_INT >= 28) {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
|
||||
window.setNavigationBarDividerColor(systemChromeStyle.systemNavigationBarDividerColor);
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowInsetsController;
|
||||
import android.view.WindowManager;
|
||||
import androidx.activity.OnBackPressedCallback;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
@ -387,6 +388,29 @@ public class PlatformPluginTest {
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
||||
}
|
||||
|
||||
@Config(sdk = 29)
|
||||
@Test
|
||||
public void verifyWindowFlagsSetToStyleOverlays() {
|
||||
View fakeDecorView = mock(View.class);
|
||||
Window fakeWindow = mock(Window.class);
|
||||
when(fakeWindow.getDecorView()).thenReturn(fakeDecorView);
|
||||
Activity fakeActivity = mock(Activity.class);
|
||||
when(fakeActivity.getWindow()).thenReturn(fakeWindow);
|
||||
PlatformChannel fakePlatformChannel = mock(PlatformChannel.class);
|
||||
PlatformPlugin platformPlugin = new PlatformPlugin(fakeActivity, fakePlatformChannel);
|
||||
|
||||
SystemChromeStyle style =
|
||||
new SystemChromeStyle(
|
||||
0XFF000000, Brightness.LIGHT, true, 0XFFC70039, Brightness.LIGHT, 0XFF006DB3, true);
|
||||
|
||||
platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style);
|
||||
verify(fakeWindow).addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
verify(fakeWindow)
|
||||
.clearFlags(
|
||||
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
|
||||
| WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void popSystemNavigatorFlutterActivity() {
|
||||
Activity mockActivity = mock(Activity.class);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user