Skip to content
Related Articles

Related Articles

Improve Article

How to Use multiline-collapsingtoolbar Library in Android App?

  • Last Updated : 11 Jul, 2021
Geek Week

Multiline-CollapsingToolbar library, as the name itself suggests, allows us to have more than one line in the CollapsingToolbarLayout. Using this library, we can deal with the multiline titles (with a customizable maximum number of lines) in the expanded state with a nice fade-away animation. In this article, we will be implementing this library in an Android App using Java language. A sample GIF is given below to get an idea about what we are going to do in this article. 

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Note: Make sure you are using android support libraries while creating a new project, since multiline-collapsingtoolbar library does not support AndroidX.

Step 2: Add the library dependency 

Navigate to the Gradle Scripts > build.gradle(Module:app), add the library in the dependencies section, and sync the project.

dependencies {
    // use the same version of Android support libraries as of collapsing toolbar
    implementation 'net.opacapp:multiline-collapsingtoolbar:27.1.1' 

Step 3: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. Comments are added inside the code to understand the code in detail.


<?xml version="1.0" encoding="utf-8"?>
        <!-- Adding CollapsingToolbarLayout-->
        <!-- maxLines sets the maximum no of lines to be displayed in expanded form-->
            app:title="GeeksForGeeks is an amazing website for DS and Algorithms. ">
                app:popupTheme="@style/AppTheme.PopupOverlay" />
    <!--Nested Scroll view contains the main_content-->
            android:text="@string/app_name" />

Step 4: Working with the styles.xml file

Navigate to the app > res > values> styles.xml and add the below code to that file. Below is the code for the styles.xml file. 


    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<!--    Sets the textSize of Title in Collapsing Toolbar-->
    <style name="TextAppearance.ExpandedTitle"
        <item name="android:textSize">26sp</item>

Step 5: Working with the file

Go to the file and refer to the following code. Below is the code for the file. 


import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState) {
        // set the toolbar as the action bar for the activity
        Toolbar toolbar = findViewById(;

Step 6: Working with the AndroidManifest.xml file

Navigate to the app > manifests > AndroidManifest.xml and add the below code in the MainActivity Tag. 



GitHub Repository: Multiline-CollapsingToolbar Library

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :