如何解决无法在Android Studio中找到符号方法addOnTabSelectedListener?我尝试添加依赖项仍然存在错误
下面是我的buid.gradle文件
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
defaultConfig {
applicationId "com.parse.starter"
minSdkVersion 21
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:23.4.0'
implementation 'com.parse.bolts:bolts-tasks:1.3.0'
implementation 'com.parse:parse-android:1.13.0'
implementation 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:design:23.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:23.4.0'
}
日志 Android资源编译失败
C:\Users\JEFF\Desktop\Instagram\ParseStarterProject\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2979: error: duplicate value for resource 'attr/layout_scrollFlags' with config ''.
C:\Users\JEFF\Desktop\Instagram\ParseStarterProject\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2979: error: resource previously defined here.
C:\Users\JEFF\Desktop\Instagram\ParseStarterProject\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3059: error: duplicate value for resource 'attr/behavior_peekHeight' with config ''.
C:\Users\JEFF\Desktop\Instagram\ParseStarterProject\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3059: error: resource previously defined here.
C:\Users\JEFF\Desktop\Instagram\ParseStarterProject\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3108: error: duplicate value for resource 'attr/layout_collapseMode' with config ''.
C:\Users\JEFF\Desktop\Instagram\ParseStarterProject\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3108: error: resource previously defined here.
C:\Users\JEFF\Desktop\Instagram\ParseStarterProject\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3230: error: duplicate value for resource 'attr/layout_anchorGravity' with config ''.
C:\Users\JEFF\Desktop\Instagram\ParseStarterProject\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3230: error: resource previously defined here.
答案 0 :(得分:0)
尝试
compile 'com.android.support:design:23.1.1'
使用
implementation "com.google.android.material:material:1.0.0"
实际用例:
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabTextColor="@color/gray"
app:tabSelectedTextColor="@color/blue"
app:tabIndicatorColor="@color/blue"
android:background="@color/white"
/>
而不是支持库,最好使用androidX
答案 1 :(得分:0)
问题: addOnTabSelectedListener API是在26.1.0版中添加的(这是一个文档错误,因为它实际上是在24.0.0-alpha2版中添加的 )。在gradle文件中,使用版本23.4.0,这就是编译器无法解析API的原因。
解决方案::如果您需要使用addOnTabSelectedListener
API,则必须更改gradle文件以使用稳定的最新版本。
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.parse.starter"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
def support_version = '28.0.0'
implementation "com.android.support:appcompat-v7:$support_version"
implementation "com.android.support:design:$support_version"
implementation "com.android.support:cardview-v7:$support_version"
implementation 'com.parse.bolts:bolts-tasks:1.4.0'
implementation 'com.parse:parse-android:1.13.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
}