The black navigation bar on the bottom of the screen is not easily removable in Android. It has been part of Android since 3.0 as a replacement for hardware buttons. Here is a picture:
How can I get the size of the width and the height of this UI element in pixels?
Here is how I solved this. I made a hideable bottom bar which needed padding depending on if there was a navigation bar or not (capacitive, on-screen or just pre lollipop).
View
Utils.java
I think more correct answer is here, because it allow you to take even cutout height too.
Take your root view, and add setOnApplyWindowInsetsListener to it (or you can override onApplyWindowInsets from it), and take insets.getSystemWindowInsets from it.
In my camera activity, i add padding equal to the systemWindowInsetBottom to my bottom layout. And finally, it fix cutout issue.
with appcompat it is like this
without appcompat, this:
The height of the bottom Navigation bar is 48dp (in both portrait and landscape mode) and is 42dp when the bar is placed vertically.
I get navigation bar size by comparing app-usable screen size with real screen size. I assume that navigation bar is present when app-usable screen size is smaller than real screen size. Then I calculate navigation bar size. This method works with API 14 and up.
Try below code:
In case of Samsung S8 none of the above provided methods were giving proper height of navigation bar so I used the KeyboardHeightProvider keyboard height provider android. And it gave me height in negative values and for my layout positioning I adjusted that value in calculations.
Here is
KeyboardHeightProvider.java
:popupwindow.xml
:Usage in
MainActivity
For any further help you can have a look at advanced usage of this here.