Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can multiline the expanded title of CollapsingToolbarLayout?

My problem is the next. I would use relatively large texts as CollapsingToolbarLayout title so I need to show it as multiline mode. When I try to change text appearance through the setExpandedTitleTextAppearance() method it doesn't work. The code who I used is the next:

<style name="ToolbarExpandedTitle">
    <item name="android:textSize">48sp</item>
    <item name="android:shadowColor">#ffffff</item>
    <item name="android:textColor">@android:color/white</item>
    <item name="android:singleLine">false</item>
    <item name="android:minLines">3</item>
    <item name="android:lines">4</item>
    <item name="android:maxLines">5</item>
</style>

enter image description here

I would like to see the title on multiple lines instead of showing the ellipsis.

like image 803
garciparedes Avatar asked Jul 15 '15 17:07

garciparedes


3 Answers

Checkout this library multiline-collapsingtoolbar.

multiline-collapsingtoolbar is a replacement for CollapsingToolbarLayout from the Android Design Support Library which can deal with multiline titles (currently hard-coded to a maximum of 3 lines) in the expanded state. When collapsing the toolbar, the lower lines of the title fade away to leave only the top line visible.

As the Design Support Library, it should be compatible with API 7 (Android 2.1) and above

like image 141
Amit Vaghela Avatar answered Oct 19 '22 00:10

Amit Vaghela


With the release of new Material Design 1.2.0-alpha05 this feature is implemented as a native function.

implement material library with version after(1.2.0-alpha05):

implementation 'com.google.android.material:material:1.2.0-alpha05'

Add this line to XML of Collapsing Toolbar Layout (this example I set 2 lines as max)

app:maxLines="2"

Alternatively you can set it programmatically

 collapsingtoolbar.setMaxLines(2);
like image 21
Eren Tüfekçi Avatar answered Oct 19 '22 02:10

Eren Tüfekçi


This doesn't seem to be supported at present. A possible workaround is to use your own view and hide the toolbar title when expanded. One approach to do this is here:

https://stackoverflow.com/a/31529101/834692

Hopefully a future version of the Support Library will add this.

like image 5
bkurzius Avatar answered Oct 19 '22 02:10

bkurzius