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|
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