如何解决找不到符号方法addOnTabSelectedListener?

问题描述 投票:0回答:2

如何解决在android studio中找不到符号方法addOnTabSelectedListener?我试过添加依赖项仍然存在错误

下面是我的build.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.
java android dependencies android-tablayout
2个回答
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


0
投票

问题:版本26.1.0中添加了addOnTabSelectedListener API(这是一个文档错误,因为它实际上是在版本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'
}
© www.soinside.com 2019 - 2024. All rights reserved.