Android Tutorial Immersive Mode with Notch area support

Brandsum

Well-Known Member
Licensed User
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"):
B4X:
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:
B4X:
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:

capisx

Member
Licensed User
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
 

capisx

Member
Licensed User
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
 

Brandsum

Well-Known Member
Licensed User
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.
 
Top