Android - how to get height of bottomnavigationview

user2362956 picture user2362956 · May 29, 2017 · Viewed 14.4k times · Source

I create a bottom navigation view. I try to get height of bottom navigation view. Material design says that the height should be 56dp. I don't want to use hard coded value, because I am not sure that this value won't change. How can I get the dimension of the view programmatically like getting status bar's height.

int resourceId =getResources().getIdentifier("status_bar_height","dimen","android");
if (resourceId > 0) {
     height = getResources().getDimensionPixelSize(resourceId);
} 

Answer

Sarthak Gandhi picture Sarthak Gandhi · May 29, 2017

You can do this by this in the onCreate method:

   bottomNavigationView.post(new Runnable() {
        @Override
        public void run() {
            int height = (int) bottomNavigationView.getMeasuredHeight();
        }
    });

This will give you height in pixels. Hope this helps