Bart Bart - 18 days ago 7
Android Question

Android toolbar show end of title

I have an application where the user can go deeper in a structure and would like to show this in the toolbar like 1 > 2 > 3 > 4

but when the toolbar is too long the end gets truncated, how can I do this to the beginning instead so the ending is always showing? I tried searching but could not find anything related.

Answer

You can use the android:ellipsize attribute to change the way text is truncated in a TextView; android:ellipsize="start" is the value you seem to be looking for.

To do this inside of a Toolbar, just replace the title with your own TextView like this:

<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:popupTheme="@style/AppTheme.PopupOverlay">

    <TextView android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:textSize="20sp"
        android:maxLines="1"
        android:ellipsize="start"/>

</android.support.v7.widget.Toolbar>
Comments