The application has a problem. Sometimes you need to display long titles. How can I do it? For example, in the VKontakte application there is a theme with a floating text, like the running line, but I can’t find such custom elements anywhere.

    1 answer 1

    Add to our Toolbar TextView :

      <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" app:contentInsetStart="0dp"> <TextView android:text="Однажды моя девушка попросила меня вынести мусор, когда я играл в доту. Знаете чем это закончилось?" android:textSize="16dp" android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </android.support.v7.widget.Toolbar> 

    This TextView will be us instead of the main one, so we assign the Toolbar title to an empty value:

     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(""); 

    Now we find our new title and assign the following parameters to it:

     TextView name = (TextView) toolbar.findViewById(R.id.name); name.setEllipsize(TextUtils.TruncateAt.MARQUEE); name.setSingleLine(true); name.setMarqueeRepeatLimit(-1); // '-1' for infinite name.setSelected(true); 

    Now the text will spin. It is worth noting that in .xml you cannot do this correctly, because android:singleLine="true" will show you that this method is deprecated , and the use of android:maxLines="1" methods android:maxLines="1" and android:lines="1" will not give you the expected result.

    • Thank you very much! It helped - Ilya Khapaev