Android Question Question about navigation bar height

Scantech

Well-Known Member
Licensed User
Longtime User
B4X:
Public Sub getNavigationBarHeight(pbolPortrait As Boolean) As Int
    Dim intHeight As Int
   
    #If B4a
    Dim strIdentifier As String
    Dim intRessourceId As Int
    Dim ctxt As JavaObject
    Dim res As JavaObject
    Dim ph As Phone
   
    ctxt.InitializeContext
    intHeight = 0
   
    If ph.SdkVersion < 14 Then
        Return 0
    End If
   
    If hasPermanentMenuKey Or Not(hasNavigationBar) Then
        Return 0
    End If
   
    If pbolPortrait Then
        strIdentifier = "navigation_bar_height"
    Else
        strIdentifier = "navigation_bar_width" ' Or navigation_bar_height_landscape?
    End If
   
    res = ctxt.RunMethodJO("getResources", Null)
    If Not(res = Null) Then
        intRessourceId = res.RunMethod("getIdentifier", Array(strIdentifier, "dimen", "android"))
        If intRessourceId > 0 Then
            intHeight = res.RunMethod("getDimensionPixelSize", Array(intRessourceId))
        End If
    End If
    #Else
    intHeight = 0
    #End If
   
    Return intHeight
End Sub

B4X:
Public Sub hasNavigationBar() As Boolean
    Dim bolHasNavBar As Boolean

    #If B4a
    Dim intRessourceId As Int
    Dim ctxt As JavaObject
    Dim res As JavaObject
    ctxt.InitializeContext
    res = ctxt.RunMethodJO("getResources", Null)
    intRessourceId = res.RunMethod("getIdentifier", Array("config_showNavigationBar", "bool", "android"))
    If intRessourceId > 0 Then
        bolHasNavBar = res.RunMethod("getBoolean", Array(intRessourceId))
    End If
   
    #Else
    bolHasNavBar = False
    #End If
   
    Return bolHasNavBar
End Sub

I have no clue what is notch? Is notch at the very top of screen? I have 132 height for notch. I do have navigation bar as seen attached. Why is navigation bar at 0 height? this code was from the other thread. I do want the height of navigation bar.
 

Attachments

  • screen (1).jpg
    screen (1).jpg
    141.4 KB · Views: 71

Scantech

Well-Known Member
Licensed User
Longtime User
I tried TargetSdk at 35. Bad results. notch and nav bar at 0 height. Emulator issue??

Has navigation bar: false
Navigation height: 0
Device has no notch. Returning 0.
Notch height: 0
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
It may be issue with emulator. With TargetSdk 36.

Pixel 6a Emulator: Nav Bar = 0, Notch = 132
Pixel 4 Emulator: Nav bar = 0, Notch = 0
S21 Ultra Real device: Nav bar = 192, Notch = 100
 
Upvote 0
Top