Search code examples
androidandroid-actionbarandroid-toolbar

Toolbar subtitle is cut (It does not fit in height)


My question is very simple, but i can't figure it out:

When i try to display a subtitle, the toolbar has not enough space do display it and it is cut.

Toolbar:

<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="?android:actionBarSize"
android:layout_centerHorizontal="true"
app:theme="@style/MyToolBar">

Does ?android:actionBarSize have not enough height to display title and subtitle correctly?

When I set ToolBar height to wrap_content everything works, but can anyone explain to me how I should correctly set the height?

styles.xml :

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowBackground">@color/background1</item>
    <item name="android:textColorPrimary">@color/colorAccent</item>

    <!-- Customize your theme here. -->
</style>

<style name="MyToolBar" parent="Widget.AppCompat.ActionBar">
    <!-- Support library compatibility -->
    <item name="android:textColorPrimary">@color/colorAccent</item>
    <item name="android:textColorSecondary">@color/colorAccent</item>
    <item name="colorControlNormal">@color/colorAccent</item>

</style>

Solution

  • I have used a toolbar with subtitles and as well as using a layout_height="wrap_content" I also add a minHeight. This will ensure your toolbar is at least the minimum height. I've not seen it jump in height or crop but I always have a subtitle set.

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