Android toolbar Title in 2 lines

How should I make a Android toolbar title display in 2 lines instead of truncating the title ?

Answers

  • @RishiNaithani Hey, simply put a TextView with maxLines into your toolbar:

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:minHeight="60dp">
    <TextView
                android:id="@+id/toolbarTitle"
                android:ellipsize="end"
                android:maxLines="2"
                android:textSize="18dp"
                android:textColor="@color/white"
                android:layout_alignParentLeft="true"
                android:layout_width="200dp"
                android:layout_height="wrap_content" />
    </android.support.v7.widget.Toolbar>
    

    This would be my solution to this.

  • RishRish USMember
    edited January 2016

    @JakubHolovsky Thanks for your time. I have tried this but it doesn't work with my code.

    I am using a left navigation drawer on the toolbar , then comes the TITLE and on the right end of the toolbar I have an image button.

    The code is as follows:

    <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?attr/actionBarSize" android:background="?attr/colorPrimary" app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/HomeButton" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_gravity="right" android:src="@drawable/ic_finalhome" android:clickable="true" /> </android.support.v7.widget.Toolbar>

    Can you help out with this.?

  • DanielBarrrosAmorimDanielBarrrosAmorim BRUniversity ✭✭

    @rishinaithani Did you find a solution to this problem?

  • ThamaraiThamarai Member ✭✭
    edited May 2018

    Hi guys,

    For toolbar having drawer icon in left side and image button at right end, we can't show full text as title in middle. Usually, Title have to be short and simple. As like in @JakubHolovsky 's answer, it is wise to show two lines of text as title. If it goes more than that, imagine how the title looks in mobile. So, it is better to keep title short and simple.

Sign In or Register to comment.