45 java xml tabs android android-studio
我的应用程序工作正常,直到我尝试添加库.添加库后,Android Studio会出现以下错误:
错误:(26)在包'inf ..'中找不到属性'layout_behavior'的资源标识符
这是我的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')
}
Run Code Online (Sandbox Code Playgroud)
这是导致错误的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"/>
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法:
但是,错误仍然存在.我该如何解决这个问题?
kri*_*son 124
该字符串资源在Material Design支持库中定义.
由于您未使用CoordinatorLayoutMaterial Design支持库,因此您应该能够安全地删除该app:layout_behavior属性.它可能是从其他代码中剪切和粘贴的.
注意:如果您实际使用CoordinatorLayout并希望协作滚动行为起作用,则需要将最新版本的Material Design Support库的依赖项添加到Gradle构建文件中:
compile 'com.android.support:design:23.0.1'
Run Code Online (Sandbox Code Playgroud)
更新:请注意,对于最新版本的Gradle,compile已弃用配置以支持implementation和api配置,因此您的依赖关系可能如下所示:
implementation 'com.android.support:design:27.0.2'
Run Code Online (Sandbox Code Playgroud)
这只是一个例子; 阅读本文时,版本号可能已过期,因此请确保您的版本与您要使用的支持库版本相匹配.
有关更多信息:gradle中的实现和编译之间有什么区别
Age*_*opf 18
注意:版本现在已更改,因此请使用最新版本替换以下版本.
如果不需要layout_behavior,接受的答案将消除错误,但是如果您确实想要使用:
app:layout_behavior="@string/appbar_scrolling_view_behavior"
Run Code Online (Sandbox Code Playgroud)
确保将正确的依赖项添加到模块的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....
}
Run Code Online (Sandbox Code Playgroud)
即将此行添加到您的依赖项:
compile 'com.android.support:design:23.1.0'
Run Code Online (Sandbox Code Playgroud)
Rob*_*Pal 14
对于那些使用AndroidX且不想添加旧库的用户:
com.android.support:design:28.0.0
Run Code Online (Sandbox Code Playgroud)
您可以添加:
implementation 'com.google.android.material:material:1.0.0'
Run Code Online (Sandbox Code Playgroud)
并像这样使用它:
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
Run Code Online (Sandbox Code Playgroud)
如果您尚未添加 android 材料,请先在 build.gradle 文件的依赖项中添加此行
implementation 'com.google.android.material:material:1.0.0'
Run Code Online (Sandbox Code Playgroud)
然后改用这个属性
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
Run Code Online (Sandbox Code Playgroud)
对于那些使用androidX的人
com.android.support:design is now moved to com.google.android.material
Run Code Online (Sandbox Code Playgroud)
您将需要包括这个
implementation 'com.google.android.material:material:1.1.0-alpha02'
Run Code Online (Sandbox Code Playgroud)
小智 5
将“ app:layout_behavior =“ @ string / appbar_scrolling_view_behavior ”替换为app:layout_behavior =“ android.support.design.widget.AppBarLayout $ ScrollingViewBehavior ”
| 归档时间: |
|
| 查看次数: |
87931 次 |
| 最近记录: |