diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index 3f18d9472ede57..bd53c2e87c1688 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -14,6 +14,7 @@ import android.view.SoundEffectConstants; import android.view.View; import android.view.Window; +import android.view.WindowManager; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; @@ -268,9 +269,10 @@ private void setSystemChromeSystemUIOverlayStyle( window.setStatusBarColor(systemChromeStyle.statusBarColor); } } - if (systemChromeStyle.systemNavigationBarDividerColor != null) { - // Not available until Android P. - // window.setNavigationBarDividerColor(systemNavigationBarDividerColor); + 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); } view.setSystemUiVisibility(flags); currentTheme = systemChromeStyle; diff --git a/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java b/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java index 0d9e0ea88e16ce..4d8cf0c55cb4b6 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java @@ -15,10 +15,12 @@ import android.content.Context; import android.media.RingtoneManager; import android.net.Uri; +import android.os.Build; import android.view.View; import android.view.Window; import io.flutter.embedding.engine.systemchannels.PlatformChannel; import io.flutter.embedding.engine.systemchannels.PlatformChannel.ClipboardContentFormat; +import io.flutter.embedding.engine.systemchannels.PlatformChannel.SystemChromeStyle; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -110,4 +112,25 @@ public void platformPlugin_hasStrings() { clipboardManager.setPrimaryClip(clip); assertFalse(platformPlugin.mPlatformMessageHandler.clipboardHasStrings()); } + + @Config(sdk = 29) + @Test + public void setNavigationBarDividerColor() { + 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, null, 0XFFC70039, null, 0XFF006DB3); + + if (Build.VERSION.SDK_INT >= 28) { + platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style); + + assertEquals(0XFF006DB3, fakeActivity.getWindow().getNavigationBarDividerColor()); + assertEquals(0XFFC70039, fakeActivity.getWindow().getStatusBarColor()); + assertEquals(0XFF000000, fakeActivity.getWindow().getNavigationBarColor()); + } + } }