Reputation: 4136
I'm trying to create something like the date selector from the new Google Calendar app. The first part of that is to create a button in the Toolbar
that fills the parent height and spans the available width. I tried to do that with the following layout:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/DefaultToolbarStyle">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
android:layout_gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="2014 Events"
android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
Normally, telling a child view (in this case the LinearLayout
) to match the parent height would make it do just that. However, the LinearLayout
only expands vertically just enough to fit its child TextView
.
How can I make children of a Toolbar
match the Toolbar
's height?
Upvotes: 1
Views: 2204
Reputation: 50538
Adding android:minHeight="?attr/actionBarSize"
and android:layout_height="?
attr/actionBarSize" will give the Toolbar
a height, that is limited and will layout children within this height.
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
style="@style/DefaultToolbarStyle">
<!--- children views --->
</android.support.v7.widget.Toolbar>
Upvotes: 4