@ -17,9 +17,6 @@ namespace Avalonia.Android.Platform
{
internal sealed class AndroidInsetsManager : WindowInsetsAnimationCompat . Callback , IInsetsManager , IOnApplyWindowInsetsListener , ViewTreeObserver . IOnGlobalLayoutListener , IInputPane
{
// For now, we check if running under net 9. TODO: remove runtime check when we target net 10
private static bool IsDisplayEdgeToEdgeForced = System . Environment . Version . Major > = 9 & & Build . VERSION . SdkInt > = ( BuildVersionCodes ) 3 5 ;
private readonly Activity _ activity ;
private readonly TopLevelImpl _ topLevel ;
private bool _d isplaysEdgeToEdge ;
@ -32,6 +29,7 @@ namespace Avalonia.Android.Platform
private Insets ? _ previousImeInset ;
private bool _d isplayEdgeToEdgePreference ;
private readonly bool _ usesLegacyLayouts ;
private readonly bool _ isDisplayEdgeToEdgeForced ;
private AndroidWindow Window = > _ activity . Window ? ? throw new InvalidOperationException ( "Activity.Window must be set." ) ;
@ -67,7 +65,7 @@ namespace Avalonia.Android.Platform
private void UpdateDisplayEdgeToEgdeState ( )
{
if ( I sDisplayEdgeToEdgeForced)
if ( _ i sDisplayEdgeToEdgeForced)
{
_d isplaysEdgeToEdge = true ;
return ;
@ -98,6 +96,9 @@ namespace Avalonia.Android.Platform
_ activity = activity ;
_ topLevel = topLevel ;
// Better detection for target sdk and running api level. Apps can change their target sdk and bypass dotnet's fixed target sdk level.
_ isDisplayEdgeToEdgeForced = _ activity . ApplicationContext ? . ApplicationInfo ? . TargetSdkVersion = = ( BuildVersionCodes ) 3 5 & & Build . VERSION . SdkInt > = ( BuildVersionCodes ) 3 5 ;
ViewCompat . SetOnApplyWindowInsetsListener ( Window . DecorView , this ) ;
if ( Build . VERSION . SdkInt < BuildVersionCodes . R )
@ -223,6 +224,12 @@ namespace Avalonia.Android.Platform
{
_ statusBarTheme = value ;
// On api 35, there's no system bar theme. Updating the status bar theme has no effect, and navigation bar now has a special style that
// makes it invisible if you change the nav bar appearance. By default, android applies a 80% opacity filter over any color drawn on the
// activity behind, forcing you to always use a light foreground, i.e. dark appearance. Thus we skip updating any colors.
if ( _ isDisplayEdgeToEdgeForced )
return ;
var compat = new WindowInsetsControllerCompat ( Window , _ topLevel . View ) ;
if ( _ isDefaultSystemBarLightTheme = = null )
@ -281,8 +288,13 @@ namespace Avalonia.Android.Platform
{
_ systemBarColor = value ;
if ( IsDisplayEdgeToEdgeForced )
if ( _ isDisplayEdgeToEdgeForced )
{
// Allow having fully transparent navbars when on api level 35
if ( OperatingSystem . IsAndroidVersionAtLeast ( 3 5 ) )
Window . NavigationBarContrastEnforced = _ systemBarColor ! = Colors . Transparent ;
return ;
}
if ( _ systemBarColor is { } color & & ! _d isplaysEdgeToEdge & & _ activity . Window ! = null )
{