no resource id found for app:layout_scrollflags from CollapsingToolbarLayout

The title of this question basically says it all. I get the error: no resource identifier found for app:layout_scrollflags from CollapsingToolbarLayout. I use eclipse and imported the design library jar file. I'm able to use the design support layouts in my classes so that's correct

this is a piece of the code i use:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/activityBg"
tools:context=".MainActivity"
>

<android.support.design.widget.AppBarLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

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

        <include
            layout="@layout/toolbar"/>

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

examples: http://android-developers.blogspot.in/2015/05/android-design-support-library.html

Answers


only importing the design library jar file is not enough. You need to import resource of android-design-library project while the jar file only contains class files.

Do as I say:

  1. import android-design-library project. The project is at "sdk/extras/android/support/design/". And set it as a library project if it is not.
  2. import the above project into your main project as a library.

You have to do this, because xmlns:app="http://schemas.android.com/apk/res-auto" means your need local resources from your library project or the current project, in this case, it means you need resources from the library project of android-design-library.


try this

add app level build.gradle

    compile 'com.android.support:design:24.2.1'

then Build -> Rebuild Project


As others have stated you definitely need to add Design Support Library dependency to your android app. Simplest way is to add following to app level gradle file -

compile 'com.android.support:design:25.3.1'

However couple of points to note-

  1. This support library should not use a different version than the compileSdkVersion. Since I was using compileSdkVersion 25 I had to use compile 'com.android.support:design:25.3.1' and not compile 'com.android.support:design:24.2.1'
  2. Using the design library requires using theme.appcompat or a descendant. If you want add actionbar to your activity then your theme should be AppCompat. In my case I was using android:Theme.Material due to which it was failing. Changing it to Theme.AppCompat.Light.NoActionBar worked for me.

For this you should use this type of hierarchy of layouts. Make sure the design support library is included as a reference project in the case of eclipse

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

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbarlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true" >

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp" >

            <ImageView
                android:id="@+id/ivProfileImage"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                app:layout_collapseMode="parallax"
                android:contentDescription="@null"
                android:fitsSystemWindows="true"
                android:minHeight="100dp"
                android:scaleType="fitXY" />

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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar"
        android:layout_gravity="fill_vertical"
        app:layout_anchorGravity="top|start"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" >
    </android.support.v4.widget.NestedScrollView>

Here is how I did

  1. Import AppCompat V7 from *

C:\Productivity\android-sdks\extras\android\support\v7\appcompat

and Check copy into workspace in import project dialog box.

  1. Target Android Build version of apcompat to Android 6.0 from

Project->Properties->Android

it should remove all compilation error.

  1. Import Design Lib from

C:\Productivity\android-sdks\extras\android\support\design

follow same steps to import project mentioned in 1 & 2.

  1. Mark imported design lib as Android lib and if it show error Add AppCompat V7 lib into Build path of your design lib from

Project->Properties->Android.

  1. Finally add design and appcompat to build path of Your Android project

    Project->Properties->Android

clean and build your project with Android 6.0 all compilation errors must be gone by now.

Congrats now you can use material design in Eclipse.Hope it will help somebody


Try add this code to the xml file:

app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"

Need Your Help

Image scaling causes poor quality in firefox/internet explorer but not chrome

html css image cross-browser scaling

See http://jsfiddle.net/aJ333/1/ in Chrome and then in either Firefox or Internet Explorer. The image is originally 120px, and I'm scaling down to 28px, but it looks bad pretty much no matter what ...

what is the equivalent test attribute for TestFixtureSetUp of Nunit in MSTest

mstest

In NUnit we use TestFixtureSetUp what is the equivalent test in MSTest?