Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the height of the Android Toolbar?

Tags:

android

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.

like image 215
Zsolt Safrany Avatar asked Jun 01 '15 10:06

Zsolt Safrany


People also ask

What is Toolbar height?

kToolbarHeight top-level constant Null safetyThe height of the toolbar component of the AppBar.

What is Toolbar size?

By default, the image size is set to the dimensions of 16 by 15 pixels. All buttons are the same width, by default 24 by 22 pixels. A toolbar's height is determined by the height of the buttons, and a toolbar's width is the same as the width of the parent window's client area, also by default.

How do I change the height of my toolbar?

You can set the height here android:minHeight="? attr/actionBarSize" in your XML. Use height and not minHeight.

What is above toolbar in android?

View above the Toolbar is officially know as status bar in android and to change color of status bar check out the answer of this question How to change the status bar color in android.


2 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

like image 184
Zsolt Safrany Avatar answered Oct 28 '22 13:10

Zsolt Safrany


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;
}
like image 33
guy.gc Avatar answered Oct 28 '22 14:10

guy.gc