Search code examples
androidbottomnavigationview

Unable to measure the height of my Bottom Navigation Bar


I'm trying to get the height of my Bottom Navigation Bar, so I can set a bottom margin on the content that is displayed above the bar. My problem is that it always returns 0. Here is the code :

navigation.post(new Runnable() {
            @Override
            public void run() {
                navHeight = navigation.getMeasuredHeight();
            }
        });

        FrameLayout frame = findViewById(R.id.frame_container);
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) frame.getLayoutParams();
        params.setMargins(0, 0, 0, navHeight);
        frame.setLayoutParams(params);

I also tried using ViewTreeObserver, but it didn't work neither.


Solution

  • I just had to move everything inside the run() method