Android Tutorial Immersive Mode with Notch area support

Original tutorial: Immersive Mode - hide the navigation bar (by @Erel )

So the above tutorial works for those devices which do not have a Notch. Devices with a notch will crop the bottom of the application content.

Solution (Project attached):
Add this code to GetRealSize sub of the original tutorial after lv.Height = point.GetField("y"):
Code: Copy
Dim r As Rect
r.Initialize(0,0,0,0)
Dim WindowVisibleDisplayFrame As JavaObject = ctxt.RunMethodJO("getWindow", Null)
WindowVisibleDisplayFrame = WindowVisibleDisplayFrame.RunMethodJO("getDecorView", Null)
WindowVisibleDisplayFrame = WindowVisibleDisplayFrame.RunMethodJO("getWindowVisibleDisplayFrame",Array(r))

If GetDeviceLayoutValues.Width > GetDeviceLayoutValues.Height Then
    lv.Width = lv.Width - r.left
Else
    lv.Height = lv.Height - r.top
End If

USE NOTCH AREA (API 28):
If it has a Notch and you want to use the Notch area then just add this code to Manifest:
Code: Copy
SetApplicationAttribute(android:theme, "@style/CustomTheme")

CreateResource(values, theme.xml,
<resources>
    <style name="CustomTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
    </style>
</resources>)
NOTE: android:windowLayoutInDisplayCutoutMode provided by the APIs in Android Pie 9.0 (API 28).
 

Attachments

Last edited:
thank you very much for your help @Brandsum.

The code above works well, since my project was in landscape so i just changed the code:
lv.Height = lv.Height - r.top
to
lv.Width = lv.Width - r.Left
 
I've tested it in landscape and If i don't change that part it will return the wrong screen size because the notch bar is in the left side off screen not in the top of screen
 
I've tested it in landscape and If i don't change that part it will return the wrong screen size because the notch bar is in the left side off screen not in the top of screen
Yup you are right. I have updated the tutorial for both orientaion.
 
Back
Top