Height of Android navigation bar (solved)

For months there were so many discussions on how to define Android navigation bar height. I finally found how to get it. There are so many “helpful-unhelpful” links that the only solution was to hide the bar at all and stop bothering yourself about the height.

As for the top status bar, then it is easy, there is a way to read its height in pixels
display.topStatusBarContentHeight, but why there is no such a way for navigation bar? It seems like it was and for no reason it was deprecated.

I found a method which will work on standard Androids where the height of the navigation bar equals to the standard value according to their design principles. According to Android documentation the height of the navbar is always 48dp (48 device independent pixels).

Look at the following table to define the height in pixels.

DPI name DPI value 48dp in physical pixels
ldpi 120 = 36.00px
mdpi 160 = 48.00px
tvdpi 213 = 63.90px
hdpi 240 = 72.00px
xhdpi 320 = 96.00px
xxhdpi 480 = 144.00px
xxxhdpi 640 = 192.00px

To convert dp to physical pixels just multiply it by 0.3

You can get DPI of your device by using a line like this
local our_DPI = system.getInfo("androidDisplayApproximateDpi")

Since I use config.lua with the following vales:

width = 720,
height = 1280, 

it was no problem to get the height of the bar using the following formula:

local our_DPI = system.getInfo("androidDisplayApproximateDpi")
local phys_pixels_int = our_DPI * 0.3
navbar_height_int = phys_pixels_int*display.contentHeight/display.pixelHeight

Done!

3 Likes

Posted this to GitHub so @vlads can take a look.

1 Like

The next step is to understand when this navbar is on and when not.
We need some kind of flag in order to determine the presence of a software navigation panel.
Hope, @vlads is almost there.

Thanks.
(10 symbol limit)

hi,
any news about this topic?

Looks like a fix has been found, it just hasn’t made it into a build yet.