Java 在包中找不到属性“layout_behavior”的资源标识符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32832717/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No resource identifier found for attribute 'layout_behavior' in package
提问by
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:
在我尝试向其中添加库之前,我的应用程序运行良好。添加库后,Android Studio 给了我以下错误:
Error:(26) No resource identifier found for attribute 'layout_behavior' in package 'inf..'
错误:(26)在包“inf..”中找不到属性“layout_behavior”的资源标识符
This is my build.gradle file:
这是我的 build.gradle 文件:
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:
这是导致错误的xml:
<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.
- 删除了库
- 重置 Android Studio 和我的电脑
- 从 git 恢复到我的代码的先前版本。
However, the error persists. How do I resolve this?
但是,错误仍然存在。我该如何解决?
采纳答案by kris larson
That string resource is defined within the Material Design support library.
该字符串资源在 Material Design 支持库中定义。
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.
由于您没有使用CoordinatorLayout
Material Design 支持库中的 ,您应该能够安全地删除该app:layout_behavior
属性。它可能是从其他代码中剪切和粘贴的。
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:
注意:如果您实际使用CoordinatorLayout
并希望协同滚动行为起作用,则需要将最新版本的 Material Design Support 库的依赖项添加到您的 Gradle 构建文件中:
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:
更新:请注意,在最新版本的 Gradle 中,compile
配置已被弃用,取而代之的是implementation
和api
配置,因此您的依赖项可能如下所示:
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
有关更多信息:在 gradle 中实现和编译有什么区别
回答by AgentKnopf
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:
在不需要 layout_behavior 的情况下,接受的答案会消除错误,但是如果您确实想使用:
app:layout_behavior="@string/appbar_scrolling_view_behavior"
Make sure to add the proper dependency to the build.gradle file of your module:
确保将适当的依赖项添加到模块的 build.gradle 文件中:
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'
回答by Julien
Just in case someone else comes from Google and makes the same mistake I did, it's layout_behaviOr
, not layout_behavioUr
.
以防万一来自 Google 的其他人犯了和我一样的错误,它是layout_behaviOr
,不是layout_behavioUr
。
回答by user3648873
Add compile com.android.support:design:23.0.1
into your build.gradle
dependencies.
将 compile 添加com.android.support:design:23.0.1
到您的build.gradle
依赖项中。
回答by Bijan Mohammadpoor
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
我有这个问题。我用两个步骤解决了我的问题。1- 在 android sdk manager 的 SDKTools 中下载最新版本的 AndroidSupportLibrary 包和 AndroidSupportRepository 包(或将它们升级到最新版本)。2- 将支持依赖项 ind build.gradle 字段更改为
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.+'
回答by Joyce obi
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.0if you are not using compile 'com.android.support:design**:23.1.0**'
AgentKnopf 回答“确保将正确的依赖项添加到模块的 build.gradle 文件”,然后我会添加,您还要确保该模块与您当前的版本相同,如下所示:compile 'com.android.support:design : 25.3.1.0如果你没有使用 compile 'com.android.support:design**:23.1.0**'
回答by Angel Koh
for those using androidX
对于那些使用 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'
回答by kdblue
I am using Androidx,so i implemented implementation 'com.google.android.material:material:1.1.0-alpha05'
我正在使用 Androidx,所以我实现了 implementation 'com.google.android.material:material:1.1.0-alpha05'
but its still giving me error Unresolved class @string/appbar_scrolling_view_behavior
但它仍然给我错误 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.
注意:在 Android Studio v3.4 中显示app:layout_behavior="@string/appbar_scrolling_view_behavior"
Unresolved 类,@string/appbar_scrolling_view_behavior
但在您运行应用程序时有效。
回答by Dilip
Replace "app:layout_behavior="@string/appbar_scrolling_view_behavior" with app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"
将“ app:layout_behavior="@string/appbar_scrolling_view_behavior”替换为app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior”
回答by Robert Pal
For those who use AndroidX and don't want to add the old library:
对于那些使用 AndroidX 并且不想添加旧库的人:
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"