No resource identifier found for attribute 'layout_behavior' in package

别来无恙 提交于 2020-02-09 05:19:47

问题


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?


回答1:


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




回答2:


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




回答3:


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'



回答4:


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"



回答5:


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' 



回答6:


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




回答7:


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.




回答8:


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"



回答9:


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.+'



回答10:


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




回答11:


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**'



来源:https://stackoverflow.com/questions/32832717/no-resource-identifier-found-for-attribute-layout-behavior-in-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!