How I can multiline the expanded title of CollapsingToolbarLayout?

前端 未结 5 1387
暖寄归人
暖寄归人 2021-02-03 20:13

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

相关标签:
5条回答
  • 2021-02-03 20:41

    A simpler approach would be to add a custom layout added to the CollapsingToolbar and pin it.

    Some of the notes to take care:

    • The the toolbar should have the height of your collapsed content, this can be done by code or at the XML.
    • The elements you want to hide must be BEFORE the toolbar definition in the layout XML file
    • The elements you want to remain visible must be AFTER the toolbar definition in the layout XML file.

    Checkout the full code here. The final result is:

    0 讨论(0)
  • 2021-02-03 20:44

    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.

    0 讨论(0)
  • 2021-02-03 20:48

    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

    0 讨论(0)
  • 2021-02-03 20:49

    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);
    
    0 讨论(0)
  • 2021-02-03 20:51

    I did this with help from this library

    https://github.com/opacapp/multiline-collapsingtoolbar

    add the library to your project and replace the CollapsingToolbarLayout with net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout

    0 讨论(0)
提交回复
热议问题