35

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

DennisVA
  • 2,068
  • 1
  • 25
  • 35

8 Answers8

29

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.

SilentKnight
  • 13,761
  • 19
  • 49
  • 78
28

try this

add app level build.gradle

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

then Build -> Rebuild Project

Thamays
  • 2,978
  • 26
  • 31
  • Will sdk level 23 work instead of 24 in this condition? – Bhunnu Baba May 02 '17 at 09:54
  • yes, you should change from compile 'com.android.support:design:23._._' to compile 'com.android.support:design:24.2.1' you need not use 24.2.1.. you can replace new version – Thamays Jun 05 '17 at 09:20
  • 'compile' is deprecated and must use 'api' (precompiled library). The version has to match your compiler. The IDE sync will provide the proper aids. – mobibob Mar 12 '21 at 23:04
6

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.
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
4

Androidx soution:

If you are using AndroidX the above solutions won't work.

You will need to implement this:

implementation 'com.google.android.material:material:1.1.0-alpha06'

Notice that Maybe you will need to Invalidate Caches/Restart for this to work for you:

File > Invalidate Caches/Restart

For more info check the Migrating to AndroidX page.

Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53
2

Try add this code to the xml file:

app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"
Saeed
  • 3,294
  • 5
  • 35
  • 52
1

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>
Gopal Singh Sirvi
  • 4,539
  • 5
  • 33
  • 55
1

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

Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154
0

Add an app level build.gradle

implementation 'com.android.support:design:28.0.0'

the version should match to your compileSdkVersion. I used version 28.

Manohar
  • 22,116
  • 9
  • 108
  • 144