| Name | Message | Date |
|---|---|---|
| 📄 EdgeToEdgeHelper.cs | 4 days ago |
📄
src/Views/EdgeToEdgeHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using Android.Views; using AndroidX.Core.View; namespace NotesApp.Views; // Under Android 15+'s forced edge-to-edge, content draws behind the status/nav bars unless // something applies their insets as padding. android:fitsSystemWindows only works for // Material's AppBarLayout, which this app doesn't use (no collapsing/scroll behavior needed), // so each screen's root view gets this explicit ViewCompat listener instead - padding all four // edges on top of whatever padding was already authored in the layout XML. public static class EdgeToEdgeHelper { public static void Apply(View root) { var baseLeft = root.PaddingLeft; var baseTop = root.PaddingTop; var baseRight = root.PaddingRight; var baseBottom = root.PaddingBottom; ViewCompat.SetOnApplyWindowInsetsListener( root, new Listener(baseLeft, baseTop, baseRight, baseBottom) ); } private class Listener(int baseLeft, int baseTop, int baseRight, int baseBottom) : Java.Lang.Object, IOnApplyWindowInsetsListener { public WindowInsetsCompat? OnApplyWindowInsets(View? v, WindowInsetsCompat? insets) { if (v is null || insets is null) return insets; var bars = insets.GetInsets(WindowInsetsCompat.Type.SystemBars())!; v.SetPadding( baseLeft + bars.Left, baseTop + bars.Top, baseRight + bars.Right, baseBottom + bars.Bottom ); return insets; } } }