Android minHeight toolbar redundant?

I built my toolbar, like most with minHeight , set to actionBarSize :

 <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto" android:background="@color/colorPrimary" android:minHeight="?actionBarSize" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> </android.support.v7.widget.Toolbar> 

However, if I remove this attribute, there is no difference. The toolbar retains its actionBarSize even if I delete the menu and set the application name to an empty String , so nothing is displayed on the toolbar.

Is there anything that I am missing here?

+5
source share
4 answers

This is a completely deliberate behavior. The minimum height of the ToolBar is set to the height of the action bar by default. so yes android:minHeight="?actionBarSize" redundunt. I could not find an official document about this, but check out this tweet.

https://twitter.com/cyrilmottier/status/814465544279691266

+1
source
 android:minHeight="?attr/actionBarSize" 

minHeight will ensure that your toolbar does not resize to ?attr/actionBarSize , no matter how small the content inside the toolbar .

EDIT

If there is nothing inside the toolbar , and if minHeight not set, the toolbar will have a default height of 56dp , which is ?attr/actionBarSize

So setting minHeight for toolbar is redundant

Read more about What is the height of the Android toolbar?

+2
source

When using both the android:layout_height="wrap_content" and android:minHeight="?attr/actionBarSize" there is a chance that your toolbar may increase in height when using larger icons.

android:minHeight ensures that your toolbar doesn't resize smaller than ?attr/actionBarSize . If you want the toolbar height to be fixed just use

android:layout_height="?attr/actionBarSize" other attribute needed.

0
source

Try it, I liked it, it works for me: -

  <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="@color/colorPrimary" android:theme="@style/AppTheme"> <LinearLayout ....... /> </android.support.v7.widget.Toolbar> 
0
source

Source: https://habr.com/ru/post/1274194/


All Articles