How can I obtain the height of the navigation bar on Android?

To obtain the navigation bar height of an Android device, you can use the following code:

public int getNavigationBarHeight(Context context) {
    Resources resources = context.getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }
    return 0;
}

By using this method, passing in a context object will return the height of the navigation bar in pixels. If the device does not have a navigation bar, it will return 0.

Please note that if your application is running in full-screen mode, the height of the navigation bar will be 0.

bannerAds