Home » Android » What's the height of the Android Toolbar?

What's the height of the Android Toolbar?

Posted by: admin April 23, 2020 Leave a comment

Questions:

What is the height of the Android Toolbar introduced in Lollipop? It’s a quite simple question but I haven’t found an answer here except for the ActionBar; but it has a different height.

How to&Answers:

The Toolbar (if not extended) has the height of:

  • 56dp (default)
  • 48dp (landscape)
  • 64dp (sw600dp; i.e. tablet)

The Toolbar is higher than the pre-lollipop ActionBar; it was 48dp by default, 40dp in landscape and 56dp in sw600dp.

And to retrieve the height of the Toolbar in XML, just use

?android:attr/actionBarSize

or if you’re using the AppCompat library this

?attr/actionBarSize

Answer:

Call this method to get the value programmatically:

public int getToolBarHeight() {
    int[] attrs = new int[] {R.attr.actionBarSize};
    TypedArray ta = getContext().obtainStyledAttributes(attrs);
    int toolBarHeight = ta.getDimensionPixelSize(0, -1);
    ta.recycle();
    return toolBarHeight;
}