【问题标题】:error can not resolve symbol TabLayout and 'design错误无法解析符号 TabLayout 和“设计”
【发布时间】:2021-03-09 20:13:22
【问题描述】:

请帮忙:导入android.support.design.widget.TabLayout时出错 它说"can not resolve symbol 'design'

我的 build.gradle:

     compileSdkVersion 26
     buildToolsVersion "26.0.0"

     dependencies {
         compile fileTree(dir: 'libs', include: ['*.jar'])
         androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
         {
             exclude group: 'com.android.support', module: 'support-annotations'
         })
         compile 'com.android.support:appcompat-v7:26'
         compile 'com.android.support.constraint:constraint-layout:1.0.2'
         compile 'com.android.support:support-v4:26'
         testCompile 'junit:junit:4.12'
     }

【问题讨论】:

    标签: android android-gradle-plugin android-support-library android-tablayout android-design-library


    【解决方案1】:

    您忘记添加设计支持库。只需在您的 gradle app 文件中添加此依赖项即可:

    implementation 'com.android.support:design:26.0.+'
    

    Design Support Library

    Design 包提供 API 以支持向您的应用添加材料设计组件和模式。

    设计支持库增加了对各种材料设计组件和模式的支持,供应用开发者在此基础上进行构建,例如 navigation drawersfloating action buttons (FAB)snackbarsTabLayout

    或AndroidX依赖:

    implementation "com.google.android.material:material:1.0.0"
    

    【讨论】:

    • 导入 TabLayout 没问题,但是 java 仍然无法解析字母“R”,我用 Gradle 同步了项目但它不起作用。你有什么想法吗?
    • 它显示错误:(46)在包'android'中找不到属性'layout_'的资源标识符
    • 我发现了错误,我只是在布局文件中打错了所以它会产生错误
    • @NadeemBhat 很乐意为您提供帮助
    【解决方案2】:

    这发生在我迁移到 androidx 时。您必须将其添加到您的 gradle 文件中:

    implementation 'com.google.android.material:material:1.1.0-alpha09'
    

    另外,TabLayout 的位置也发生了变化。来自

    android.support.design.widget.TabLayout
    

    com.google.android.material.tabs.TabLayout
    

    这里是 androidx 的 class mappings。 这是新的documentation for the TabLayout

    【讨论】:

      【解决方案3】:

      更新:

      使用 AndroidxMaterial Components library 使用:

      implementation 'com.google.android.material:material:1.0.0'
      

      OLD(支持库):

      如果你想使用TabLayout,你可以签入doc,你必须添加这个依赖:

      com.android.support:design:26.0.2
      

      dependencies 块中添加您的build.gradle

      compile 'com.android.support:design:26.0.2'
      

      【讨论】:

        【解决方案4】:

        替换为:

        android.support.design.widget.TabLayout
        

        有了这个:

        import com.google.android.material.tabs.TabLayout;
        

        为我工作! ;-)


        你需要添加到build_gradle(APP):

        implementation 'com.google.android.material:material:1.0.0'
        

        【讨论】:

          猜你喜欢
          • 2015-12-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-24
          • 2019-12-30
          • 1970-01-01
          相关资源
          最近更新 更多