13
13
using Microsoft . Identity . Client . PlatformsCommon ;
14
14
using Microsoft . Identity . Client . PlatformsCommon . Shared ;
15
15
using Microsoft . Identity . Client . Utils ;
16
+ #if __ANDROID_30__
17
+ using AndroidX . Core . View ;
18
+ using AndroidX . Core . Graphics ;
19
+ #endif
16
20
17
21
namespace Microsoft . Identity . Client . Platforms . Android . EmbeddedWebview
18
22
{
19
23
[ Activity ( ConfigurationChanges = ConfigChanges . Orientation | ConfigChanges . ScreenSize , Exported = false ) ]
20
24
internal class AuthenticationAgentActivity : Activity
21
25
{
22
26
private const string AboutBlankUri = "about:blank" ;
27
+ private const int ApiLevelVanillaIceCream = 35 ; // Android API 35 (Vanilla Ice Cream)
23
28
private CoreWebViewClient _client ;
24
29
25
30
protected override void OnCreate ( Bundle bundle )
26
31
{
27
32
base . OnCreate ( bundle ) ;
33
+
34
+ // Enable edge-to-edge for Android API 30+
35
+ EnableEdgeToEdge ( ) ;
36
+
28
37
// Create your application here
29
-
30
38
WebView webView = new WebView ( this ) ;
31
39
var relativeLayout = new RelativeLayout ( this ) ;
32
40
webView . LayoutParameters = new RelativeLayout . LayoutParams ( RelativeLayout . LayoutParams . MatchParent , RelativeLayout . LayoutParams . MatchParent ) ;
33
41
34
42
relativeLayout . AddView ( webView ) ;
35
43
SetContentView ( relativeLayout ) ;
44
+
45
+ // Apply window insets for edge-to-edge layout
46
+ ApplyWindowInsets ( relativeLayout , webView ) ;
36
47
37
48
string url = Intent . GetStringExtra ( "Url" ) ;
38
49
@@ -51,6 +62,36 @@ protected override void OnCreate(Bundle bundle)
51
62
webView . LoadUrl ( url ) ;
52
63
}
53
64
65
+ private void EnableEdgeToEdge ( )
66
+ {
67
+ #if __ANDROID_30__
68
+ if ( Build . VERSION . SdkInt >= BuildVersionCodes . R ) // API 30+
69
+ {
70
+ // Enable edge-to-edge
71
+ Window . SetDecorFitsSystemWindows ( false ) ;
72
+
73
+ // For API 35+, ensure proper edge-to-edge behavior
74
+ if ( ( int ) Build . VERSION . SdkInt >= ApiLevelVanillaIceCream )
75
+ {
76
+ // Additional API 35 specific configurations using SetStatusBarColor/SetNavigationBarColor methods
77
+ Window . SetStatusBarColor ( global ::Android . Graphics . Color . Transparent ) ;
78
+ Window . SetNavigationBarColor ( global ::Android . Graphics . Color . Transparent ) ;
79
+ }
80
+ }
81
+ #endif
82
+ }
83
+
84
+ private void ApplyWindowInsets ( RelativeLayout parentLayout , WebView webView )
85
+ {
86
+ #if __ANDROID_30__
87
+ if ( Build . VERSION . SdkInt >= BuildVersionCodes . R ) // API 30+
88
+ {
89
+ ViewCompat . SetOnApplyWindowInsetsListener ( parentLayout , new OnApplyWindowInsetsListener ( webView ) ) ;
90
+ ViewCompat . RequestApplyInsets ( parentLayout ) ;
91
+ }
92
+ #endif
93
+ }
94
+
54
95
public override void Finish ( )
55
96
{
56
97
if ( _client . ReturnIntent != null )
@@ -193,5 +234,38 @@ private void Finish(Activity activity, string url)
193
234
activity . Finish ( ) ;
194
235
}
195
236
}
237
+
238
+ #if __ANDROID_30__
239
+ private class OnApplyWindowInsetsListener : Java . Lang . Object , AndroidX . Core . View . IOnApplyWindowInsetsListener
240
+ {
241
+ private readonly WebView _webView ;
242
+
243
+ public OnApplyWindowInsetsListener ( WebView webView )
244
+ {
245
+ _webView = webView ;
246
+ }
247
+
248
+ public WindowInsetsCompat OnApplyWindowInsets ( global ::Android . Views . View v , WindowInsetsCompat insets )
249
+ {
250
+ var systemBarsInsets = insets . GetInsets ( WindowInsetsCompat . Type . SystemBars ( ) ) ;
251
+ var imeInsets = insets . GetInsets ( WindowInsetsCompat . Type . Ime ( ) ) ;
252
+
253
+ // Apply margins to avoid system UI overlap
254
+ var layoutParams = _webView . LayoutParameters as RelativeLayout . LayoutParams ;
255
+ if ( layoutParams != null )
256
+ {
257
+ layoutParams . SetMargins (
258
+ systemBarsInsets . Left ,
259
+ systemBarsInsets . Top ,
260
+ systemBarsInsets . Right ,
261
+ Math . Max ( systemBarsInsets . Bottom , imeInsets . Bottom )
262
+ ) ;
263
+ _webView . LayoutParameters = layoutParams ;
264
+ }
265
+
266
+ return insets ;
267
+ }
268
+ }
269
+ #endif
196
270
}
197
271
}
0 commit comments