Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: attribute 'package:contentScrim' not found

While I am trying to do Collapsing Toolbar Layout I got the error on contentScrim not found. This is my XML file.

<?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/htab_maincontent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/htab_appbar"
        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/htab_collapse_toolbar"
        android:layout_width="match_parent"
        android:layout_height="256dp"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
        app:titleEnabled="false">

        <ImageView
            android:id="@+id/htab_header"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/header"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"/>

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:alpha="0.3"
            android:background="@android:color/black"
            android:fitsSystemWindows="true"/>

        <android.support.v7.widget.Toolbar
            android:id="@+id/htab_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_gravity="top"
            android:layout_marginBottom="48dp"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/htab_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:tabIndicatorColor="@android:color/white"
            app:tabSelectedTextColor="@android:color/white"
            app:tabTextColor="@color/white_70"/>

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

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

    <android.support.v4.view.ViewPager
        android:id="@+id/htab_viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

I have seen all the tutorial on GitHub and other sites. and used but I could not get the solution. Any easy way to the parallax sticky header for the fragment. and right now I am following the code of https://android.jlelse.eu/parallax-scrolling-header-tabs-android-tutorial-2cc6e40aa257 and see the documentation of android developer about the CollapsingToolbarLayout.

like image 520
sanjay Avatar asked Jan 04 '18 09:01

sanjay


People also ask

What is CollapsingToolbarLayout?

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 .

What is layout_collapseMode?

In addition to pinning a view, you can use app:layout_collapseMode="parallax" (and optionally app:layout_collapseParallaxMultiplier="0.7" to set the parallax multiplier) to implement parallax scrolling (say of a sibling ImageView within the CollapsingToolbarLayout ).

How to set title in Collapsing Toolbar?

collapsingToolbarLayout. setTitleEnabled(false); toolbar. setTitle("My Title"); By calling setTitleEnabled(false); , the title appeared in the toolbar.


2 Answers

I don't know why exactly you would be getting that error, but this might be a good start.

https://stackoverflow.com/a/31180719/7900721

Otherwise I found this really good tutorial on mastering the coordinator layout which has a github repo with a bunch of great examples with the collapsing toolbar layout that helped me when I developed one.

http://saulmm.github.io/mastering-coordinator

like image 142
Andrew Steinmetz Avatar answered Sep 23 '22 06:09

Andrew Steinmetz


Try adding this to your app build.gradle:

dependencies {
...
    implementation 'com.google.android.material:material:1.1.0'
...
}
like image 23
jon Avatar answered Sep 21 '22 06:09

jon