54

My application worked fine until I tried to add a library to it. After I added the library, Android Studio gives me the following error:

Error:(26) No resource identifier found for attribute 'layout_behavior' in package 'inf..'

This is my build.gradle file:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.ogaclejapan.smarttablayout:utils-v4:1.3.0@aar'
    compile 'com.ogaclejapan.smarttablayout:library:1.3.0@aar'
    compile 'com.jpardogo.materialtabstrip:library:1.1.0'
    // compile 'com.lorentzos.swipecards:library:1.0.9@aar'
    compile 'com.android.support:cardview-v7:21.0.3'
    compile 'com.android.support:recyclerview-v7:21.0.3'
    compile 'com.melnykov:floatingactionbutton:1.3.0'
    compile project(':swipelib')
}

This is the xml which causes the error:

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

I tried the following:

  • Removed the library
  • Reset Android Studio and my computer
  • Reverted to previous version of my code from git.

However, the error persists. How do I resolve this?

M.Ricciuti
  • 11,070
  • 2
  • 34
  • 54

11 Answers11

131

That string resource is defined within the Material Design support library.

Since you're not using the CoordinatorLayout from the Material Design support library, you should be able to safely remove the app:layout_behavior attribute. It was probably cut & paste from other code.

NOTE: If you are actually using CoordinatorLayout and want the cooperative scrolling behaviors to work, you need to add the dependency for the latest version of the Material Design Support library to your Gradle build file:

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

UPDATE: Note that with the latest versions of Gradle the compile configuration has been deprecated in favor of implementation and api configurations so your dependency could look like this:

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

This is only an example; the version numbers may be out of date when you read this, so make sure your version matches the version of the support library that you want to use.

For more info: What's the difference between implementation and compile in gradle

kris larson
  • 30,387
  • 5
  • 62
  • 74
  • Please be sure that you are using the latest version of the design library. In order to get the latest version check the official page of the design library. https://developer.android.com/training/material/design-library.html#AddDependency As of writing this comment the latest version is ```compile 'com.android.support:design:25.3.1' ``` – Aksel Fatih May 26 '17 at 11:26
  • In app/build.gradle I put version 26.1.0 within "dependencies{compile 'com.android.support:design:26.1.0}" _ it works thanks! @kris larson! – Dung Aug 27 '18 at 19:44
45

Just in case someone else comes from Google and makes the same mistake I did, it's layout_behaviOr, not layout_behavioUr.

frogatto
  • 28,539
  • 11
  • 83
  • 129
Julien
  • 4,434
  • 3
  • 16
  • 19
24

For those who use AndroidX and don't want to add the old library:

com.android.support:design:28.0.0

you can add instead:

implementation 'com.google.android.material:material:1.0.0'

and use it like this:

app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
Robert Pal
  • 714
  • 1
  • 7
  • 15
  • 3
    In addition, `app:layout_behavior="@string/appbar_scrolling_view_behavior"` also works after adding the material library. – vanogrid Jul 21 '19 at 01:27
18

Note: The versions have changed by now, so replace below versions with the most recent ones.

The accepted answer gets rid of the error in case layout_behavior is not needed, however if you actually want to use:

app:layout_behavior="@string/appbar_scrolling_view_behavior"

Make sure to add the proper dependency to the build.gradle file of your module:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "21.1.2"

   //Other stuff....
}

dependencies {

    //Importing the design library fixes the build
    compile 'com.android.support:design:23.1.0'

    //Other libraries....
}

I.e. add this line to your dependencies:

compile 'com.android.support:design:23.1.0'
AgentKnopf
  • 4,295
  • 7
  • 45
  • 81
  • 3
    but how on earth would you know that `com.android.support:design:23.1.0` is the solution to a broken `app:layout_behavior = "@string/appbar_scrolling_view_behavior"` – dsdsdsdsd Apr 20 '16 at 15:12
  • @dsdsdsdsd I just tried it out, as I was having the same problem at some point – AgentKnopf Jun 02 '16 at 08:49
  • my library already has this dependency still it shows same error. When I add design library to app project gradle dependency then it goes away. Why do i have to add it to app project when it's already there in library? any solution? – nayakasu Apr 07 '17 at 11:15
  • @Asu Not sure what's going on there, but also beware that the versions have changed by bow - so you should use the most recent design library version. You could check if you find some information regarding the behavior you mentioned here: https://developer.android.com/studio/build/dependencies.html – AgentKnopf Jun 10 '17 at 20:37
7

if you not added android material yet first add this line in your dependencies in build.gradle file

implementation 'com.google.android.material:material:1.0.0'

then use this attribute instead

app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
smarteist
  • 1,331
  • 12
  • 15
  • Even i was getting this error in "compileSdkVersion 29". So, I have added this line implementation 'com.google.android.material:material:1.0.0'. It resolved the error. – user1628121 Jan 20 '20 at 06:01
6

for those using androidX

com.android.support:design is now moved to com.google.android.material

you will need to include this

implementation 'com.google.android.material:material:1.1.0-alpha02' 
Angel Koh
  • 12,479
  • 7
  • 64
  • 91
5

Replace "app:layout_behavior="@string/appbar_scrolling_view_behavior" with app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"

Dilip
  • 203
  • 3
  • 5
4

I am using Androidx,so i implemented implementation 'com.google.android.material:material:1.1.0-alpha05'

but its still giving me error Unresolved class @string/appbar_scrolling_view_behavior

so i found just Invalidate caches / Restart

Quickest way to do that is File → Invalidate caches / Restart... → Just Restart.

I hope its help you.

Note: In Android Studio v3.4 showing app:layout_behavior="@string/appbar_scrolling_view_behavior" Unresolved class @string/appbar_scrolling_view_behavior but work when you run your app.

iamkdblue
  • 3,448
  • 2
  • 25
  • 43
  • thx, Just Restart make it work in v3.4 , but several minutes later, it auto turned red – Gavin Andre Apr 24 '19 at 11:21
  • I have migrated to androidx packages (i.e. implementation 'com.google.android.material:material:1.0.0'), and am seeing this same thing. I invalidated caches and restarted, red error went away for just a few seconds, then came back. – tfrysinger Apr 26 '19 at 17:04
  • @tfrysinger run your app its work and the red error always exists until next update :) – iamkdblue Apr 26 '19 at 17:40
  • 1
    It only occurs in new Android Studio 3.4. Following the issue here https://issuetracker.google.com/issues/131403371 – Hai Hack Apr 30 '19 at 22:50
  • @kdblue you are correct. In Android Studio v3.4 , showing app:layout_behavior="@string/appbar_scrolling_view_behavior" Unresolved class @string/appbar_scrolling_view_behavior but work when you run your app. – stay_hungry Dec 07 '19 at 13:47
1

I have this problem. and i resolved my problem with tow steps. 1- Download last version of AndroidSupportLibrary package and AndroidSupportRepository package(or upgarad them to the newest version) in SDKTools of android sdk manager . 2- Change support depenedencies ind build.gradle fiel to

compile 'com.android.support:appcompat-v7:25.+'
compile 'com.android.support:support-v4:25.+'
compile 'com.android.support:recyclerview-v7:25.+'
compile 'com.android.support:design:25.+'
0

Add compile com.android.support:design:23.0.1 into your build.gradle dependencies.

The SE I loved is dead
  • 1,517
  • 4
  • 23
  • 27
0

AgentKnopf Answer "Make sure to add the proper dependency to the build.gradle file of your module", then I would add, you also make sure the module is same as your current version like this: compile 'com.android.support:design:25.3.1.0 if you are not using compile 'com.android.support:design**:23.1.0**'

Joyce obi
  • 59
  • 1
  • 11