Android Tutorial Immersive Mode with Notch area support

Discussion in 'Tutorials & Examples' started by Brandsum, Dec 20, 2018.

  1. Brandsum

    Brandsum 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"):
    Code:
    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:
    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).
     

    Attached Files:

    Last edited: Dec 21, 2018
  2. capisx

    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
     
  3. capisx

    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
     
  4. Brandsum

    Brandsum Member Licensed User

    Yup you are right. I have updated the tutorial for both orientaion.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice