Android - how to get height of bottomnavigationview

bottomnavigationview item padding
android get status bar height
bottomnavigationview setselecteditemid
android setonnavigationitemselectedlistener
bottomnavigationview badge
bottomnavigationview icon color
get bottom navigation bar height
bottom navigation drawer android

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

How can i get the height of BottomNavigationView using XML , height of BottomNavigationView height using XML attribute just like this ?attr/​actionBarSize <com.google.android.material.bottomnavigation. com.google.android.material.bottomnavigation.BottomNavigationView. Represents a standard bottom navigation bar for application. It is an implementation of material design bottom navigation. Bottom navigation bars make it easy for users to explore and switch between top-level views in a single tap.

This is basic code for achieve the height of BottomNavigationView,

int resourceId = getResources().getIdentifier("design_bottom_navigation_height", "dimen", this.getPackageName());
        int height = 0;
        if (resourceId > 0) {
            height = getResources().getDimensionPixelSize(resourceId);
        }
        //height in pixels
        Toast.makeText(this, height + "", Toast.LENGTH_SHORT).show();
        // if you want the height in dp
        float density = getResources().getDisplayMetrics().density;
        float dp = height / density;
        Toast.makeText(this, dp + "", Toast.LENGTH_SHORT).show();

BottomBar height not 56dp · Issue #168 · roughike/BottomBar · GitHub, The height of the bottom bar should be 56dp according to the Material @hpost i have override the BB_BottomBarItem_Fixed style ,but it not take effect. <item name="android:gravity">bottom|center_horizontal</item> <item @coderlife I would suggest to use icons with dimensions of 24dp x 24dp. How to change the size of BottomNavigationView icons. BottomNavigationView is a class which is used in Android to provide user a better and easier way to switch between the top-level views in a single tap. I am assuming that you are aware of BottomNavigationView, If you are not then I suggest you go through the below-provided blog link

Here is another approach. To get the height of BottomNavigationView programatically, I use ViewTreeObserver. This allows me to get the right value of the view after its drawn. Below is the sample code:

BottomNavigationView mBottomNavigation= findViewById(R.id.navigation);
    ViewTreeObserver viewTreeObserver = mBottomNavigation.getViewTreeObserver();
            if (viewTreeObserver.isAlive()) {
                viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        int viewHeight = mBottomNavigation.getHeight();
                        if (viewHeight != 0)
                            mBottomNavigation.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        //viewWidth = mBottomNavigation.getWidth(); //to get view's width
                    }
                });
            }

It is very important to remove viewObserver listener once we get the view's height, I am removing viewObserver using:

removeOnGlobalLayoutListener(this)

So that it stops listening to every change in that view.

[BottomNavigationView] Bottom Navigation View Sizing · Issue #431 , For the BottomNavigationView I set a height of 56dp, an itemIconSize of 24dp @wcshi indicated in #499 that a fixed height would make the icons and tex BottomNavigationView android:id="@+id/bottom_navigation_view"  Hey, Android Developer. I would like to tell you something about Android Bottom Navigation View. The Bottom Navigation View is a part of the Google Android Material Design Library. It creates a bottom navigation bar, making it easier to explore switch between with a single tap. Let’s start with Bottom Navigation View

How to measure the new Bottom Navigation on Android, The idea to show icon and a label when you have 3 tabs and to show Ideally, on this size of the screen an app should switch to a different  This allows it to get a callback in onDependentViewChanged when the Snackbar appears and moves. Now, in order to get a smooth movement transition the FAB needs to move up together with the Snackbar. The way Snackbars are animated in is by translating them up by their entire height.

BottomNavigationView, public class BottomNavigationView Bottom navigation bars make it easy for users to explore and switch between final int, getHeight(). As stated in the MainActivity class, the instance of the BottomNavigationView inflates a menu layout. Under the res folder of your project, create a menu folder if it does not exist. Inside the menu folder, create a menu resource file and name it bottom_menu.xml. Open the file and add the code below.

Android bottom navigation bar size and padding, Android answer from SO: I get navigation bar size by comparing app-usable screen size with real screen size. I assume that navigation bar is  The material design team at Google defines the functionality of bottom navigation bars in Android as follows: Bottom navigation bars make it easy to explore and switch between top-level views in a single tap. Tapping on a bottom navigation icon takes you directly to the associated view or refreshes the currently active view.

Comments
  • It's name is "design_bottom_navigation_height", and it would be in your package, so replace "android" with getPackageName().
  • @MikeM. activity.getResources().getIdentifier("design_bottom_navigation_height", "dimen", "android"); returns 0. it is invalid resource id.
  • "...it would be in your package, so replace "android" with getPackageName()."
  • You are right. I convert it to dp. The value is 168. it is weight, not heigh.
  • Huh? There's no weight involved here. It's a definite measure, in pixels. If you want dp, you need to take the display density into account. You shouldn't really need the dp measure in code, though. Pretty much everything deals in pixels.