Aftab Safdar
Aftab Safdar

Reputation: 668

Why is my Button hidden when using CollapsingToolbar

I have a simple Activity with a CollapsingToolbar. Let me show you what I have 1st and then explain what the problem is!

When the toolbar is collapsed (left) vs when it is expanded (right)

collapsed Toolbar expanded Toolbar

As you can see, the Search button doesn't show when the toolbar is expanded. How can I fix this?

activity_search.xml :

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:fitsSystemWindows="true"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_collapseMode="parallax"/>

            <android.support.v7.widget.Toolbar
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay"/>

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

    <include
        layout="@layout/content_search" />
</android.support.design.widget.CoordinatorLayout>

content_search.xml

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/ll"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="@dimen/view_margin"
        android:orientation="horizontal">

        <AutoCompleteTextView
            android:id="@+id/etIngredients"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>

        <ImageButton
            android:id="@+id/btAdd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_add"/>
    </LinearLayout>

    <Button
        android:id="@+id/btSearch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="@string/search"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rvIngredients"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/btSearch"
        android:layout_below="@id/ll"/>
</RelativeLayout>

I have tried searching for this question, but could'nt find anything at all!

Upvotes: 0

Views: 152

Answers (3)

Neo
Neo

Reputation: 3584

It is hidden due to your collapsable toolbar. When you say match_parent it takes height excluding the height of expanded toolbar. All you need to do is add bottom_margin of expended toolbar height.

Hope it will help you :)

Upvotes: 1

Sachin
Sachin

Reputation: 1448

Please check your content_search.xml

what is id android:layout_below="@id/ll"??

i think this is id of linear layout, please add this and run hope it will help you.

Upvotes: 1

user6464793
user6464793

Reputation:

Try modifying your content_search.xml thus:

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginBottom="@dimen/view_margin"
    android:orientation="horizontal">

    <AutoCompleteTextView
        android:id="@+id/etIngredients"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>

    <ImageButton
        android:id="@+id/btAdd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_add"/>
</LinearLayout>

<android.support.v7.widget.RecyclerView
    android:id="@+id/rvIngredients"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

<Button
    android:id="@+id/btSearch"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:text="@string/search"/>
</LinearLayout>

And if you don't need to have your search button right at the bottom of the screen, move it above the RecyclerView.

Upvotes: 2

Related Questions