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);
}
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