no resource id found for app:layout_scrollflags from CollapsingToolbarLayout
Asked Answered
S

8

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

Sturrock answered 2/7, 2015 at 8:33 Comment(2)
BTW this need to be in an AppBarLayout inside a CoordinatorLayout.Galway
still not working after putting it in a appbarlayoutSturrock
K
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.

Kellerman answered 2/7, 2015 at 9:27 Comment(2)
i got errors in design library after importing at style.xml fileHerdsman
Can you provide more details?Kellerman
P
28

try this

add app level build.gradle

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

then Build -> Rebuild Project

Prior answered 11/10, 2016 at 10:25 Comment(3)
Will sdk level 23 work instead of 24 in this condition?Ce
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 versionPrior
'compile' is deprecated and must use 'api' (precompiled library). The version has to match your compiler. The IDE sync will provide the proper aids.Maclaine
H
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.
Hertfordshire answered 1/4, 2017 at 10:8 Comment(0)
C
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.

Chiffon answered 1/6, 2019 at 9:22 Comment(0)
M
2

Try add this code to the xml file:

app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"
Muley answered 2/5, 2019 at 4:8 Comment(0)
U
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>
Unknowing answered 2/7, 2015 at 8:44 Comment(6)
still doesn't work after i put the whole thing in a appbarlayoutSturrock
try to remove linear layout and put it in a cordinator layout and the other content in nested scroll view. I recently implemented it and it is working fineUnknowing
did u use eclipse or android studio?Sturrock
did you add any jars to get the design support library to work other then appcompat v4/v7Sturrock
No just used the project design (design support library) from sdk as a reference project.Unknowing
Let us continue this discussion in chat.Unknowing
D
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

Delvalle answered 13/2, 2016 at 6:52 Comment(0)
Z
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.

Zirconium answered 14/5, 2019 at 8:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.