Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Menu options not showing on Collapsing Toolbar

I am trying to implement a Collapsing Toolbar Layout with menu options but whenever I set the image view source in the below code, the image covers the menu and the back button. The options are there as I can click on them, they are just hidden by the image. Does anyone know how to fix this?

XML Layout

    <android.support.design.widget.AppBarLayout android:id="@+id/app_bar"
        android:layout_width="match_parent" android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/toolbar_layout"
            android:layout_width="match_parent" android:layout_height="match_parent"
            android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed" app:toolbarId="@+id/toolbar">

            <android.support.v7.widget.Toolbar android:id="@+id/detail_toolbar"
                android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                android:fitsSystemWindows="true"/>

            <ImageView
                android:src="@drawable/background"
                app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"
                android:minHeight="100dp"
                android:fitsSystemWindows="true"/>

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

</android.support.design.widget.AppBarLayout>
like image 604
Carl Avatar asked Dec 06 '15 20:12

Carl


People also ask

What is collapsing toolbar layout?

CollapsingToolbarLayout is a wrapper for Toolbar which implements a collapsing app bar. It is designed to be used as a direct child of a AppBarLayout .

How do you add a title to a collapsing toolbar?

By calling setTitleEnabled(false); , the title appeared in the toolbar. Save this answer. Show activity on this post. It is the same as setting title in a normal toolbar.

What is contentScrim in Android?

app:contentScrim: Specifies drawable or Color value when scrolled sufficiently off screen. app:layout_collapseMode: Specifies how child views of collapsing toolbar layout move when layout is moving. Parallax- moves in parallax fashion, Pin-view placed in fixed position.


3 Answers

Try adding collapseMode attributes to the Toolbar...like this. It pins the toolbar.

<android.support.v7.widget.Toolbar


    app:layout_collapseMode="pin" />
like image 69
Suman Astani Avatar answered Oct 08 '22 12:10

Suman Astani


please try this :

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true" >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" >

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:toolbarId="@+id/toolbar" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_collapseMode="parallax"
                android:background="@drawable/background"
                android:fitsSystemWindows="true"
                android:minHeight="100dp"
                android:scaleType="centerCrop" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/detail_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                android:fitsSystemWindows="true"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

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

if any trouble leave comment

good luck !

like image 8
Netero Avatar answered Oct 14 '22 17:10

Netero


From own experience this tells me this you probably have forgotten to add the following lines to the activity:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

setSupportActionBar(toolbar);

like image 7
Ove Stoerholt Avatar answered Oct 14 '22 15:10

Ove Stoerholt