Search code examples
androidandroid-collapsingtoolbarlayoutandroid-appbarlayout

How can i set the minimum height of a collapsingToolbar in android?


I have a collapsingToolbarLayout, How can i change its minimum height ? i have tried in xml minHeight="100dp" but it dosent work. It collapses to the till the top like it usually should. Can anyone tell me how can i set its minimum height to lets say 150dp ?

 <android.support.design.widget.CoordinatorLayout
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:fitsSystemWindows="true"
            app:layout_constraintBottom_toTopOf="@+id/bottom_nav_master_home"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <android.support.design.widget.AppBarLayout
                android:id="@+id/app_bar_master_home_activity"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="?attr/colorPrimary"
                android:fitsSystemWindows="true"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

                <android.support.design.widget.CollapsingToolbarLayout
                    android:id="@+id/toolbar_collapse"
                    android:layout_width="match_parent"
                    android:layout_height="256dp"
                    android:layout_marginBottom="100dp"
                    android:fitsSystemWindows="true"
                    app:contentScrim="?attr/colorPrimary"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
                    app:titleEnabled="false">

                    <android.support.constraint.ConstraintLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@color/color_master_background_dark"
                        app:layout_collapseMode="parallax
                        android:background="@color/color_master_background_dark"
                        android:fitsSystemWindows="true"
                        android:scaleType="centerCrop"
                        app:layout_collapseMode="parallax" />
                    <android.support.v7.widget.Toolbar
                        android:id="@+id/toolbar_master_home_activity"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
                        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                        app:title=" "
                        app:titleTextColor="@color/color_text_dark" />

                </android.support.design.widget.CollapsingToolbarLayout>

            </android.support.design.widget.AppBarLayout>

            <fragment
                android:id="@+id/fragment_nav_host_main_master"
                android:name="androidx.navigation.fragment.NavHostFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:defaultNavHost="true"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                app:navGraph="@navigation/nav_graph_master_main" />

        </android.support.design.widget.CoordinatorLayout>

i did add the marginBottom but still no result ? Am i doing something wrong here ? i edited the above code ..


Solution

  • Set bottom margin of your Toolbar to whatever space you want to be reserved in the collapsed version.
    Source - setting minHeight in CollapsingToolbarLayout not having any effect