Height versus MinHeight toolbar

I recently upgraded 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?

Do I need to use both attributes?

+3


source to share


3 answers


  • When using both attributes , there is a possibility that the height of your toolbar may increase when using larger icons. android:layout_height="wrap_content"

    android:minHeight="?attr/actionBarSize"

  • android:minHeight

    makes sure your toolbar doesn't resize smaller . ?attr/actionBarSize

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



android:layout_height="?attr/actionBarSize"

      

No other attribute is needed.

+8


source


What is the difference between these two attributes?

android:minHeight

Determines the minimum height of the view.
android:layout_height

Determines the base height of the view.

Pseudocode for more clarity.

if(minHeightDefined) {
    if(currentHeightOfView < minHeight) {
        currentHeightOfView = minHeight;
    } else {
        currentHeightOfView = layout_height;
    }
} else {
    currentHeightOfView = layout_height;
}

      



minHeightDefined

- flag indicates what is android:minHeight

declared in xml file format or not

Why is layout_height set to wrap_content in ToolBar documentation?

Because it is the default.

+2


source


Ok, when you give android: layout_height = "wrap_content" then your toolbar can shrink if it doesn't contain a larger child view and then the default size of the action bar.

But if you specify android: minHeight = "? Attr / actionBarSize" it doesn't matter how small the toolbar view maintains its default ActionBar size.

+1


source







All Articles