Search code examples
javaandroidmaterial-designandroid-toolbarappcompatactivity

Height vs minHeight Toolbar


I recently updated to AppCompatActivity and switched from ActionBar to ToolBar.

When I was checking the xml, I found these two attributes -

android:layout_height="wrap_content"

and

android:minHeight="?attr/actionBarSize"

What is the difference between these two attributes? Why is layout_height set to wrap_content in the ToolBar documentation?

Is it necessary to use both the attributes?


Solution

    • On using both the attributes, android:layout_height="wrap_content" and android:minHeight="?attr/actionBarSize", there is a possibility that your toolbar height may get larger when you use larger icons.
    • android:minHeight ensures that your toolbar will not resize itself smaller than ?attr/actionBarSize value.

    If you want your toolbar height to be fixed, just use

    android:layout_height="?attr/actionBarSize"
    

    The other attribute is not needed.