簡體   English   中英

為什么 Android Studio 看不到“android.support.design.widget.CoordinatorLayout”?

[英]Why doesn't Android Studio see 'android.support.design.widget.CoordinatorLayout'?

我是 Android 的初學者。 我在build.gradle中包含了'com.android.support:appcompat-v7:28.0.0''com.android.support:design:28.0.0'

build.gradle:

plugins {
    id 'com.android.application'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.financialapp"
        minSdk 27
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildFeatures {
        viewBinding true
    }
}



dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
    implementation 'androidx.navigation:navigation-fragment:2.4.1'
    implementation 'androidx.navigation:navigation-ui:2.4.1'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'


    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'com.google.android.flexbox:flexbox:3.0.0'

}

我想在 XML 文件中使用 ''android.support.design.widget.CoordinatorLayout' 但出現錯誤。

錯誤:

error: package android.support.design.widget does not exist
import android.support.design.widget.CoordinatorLayout;

因為你沒有對材料的依賴

在你的 build.gradle(:app) 里面

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

版本 28(適用於 Android Pie 及以下版本)是舊版支持庫的最后一個版本,因此我們建議您在使用 Android Q 並繼續前進時遷移到 AndroidX 庫。 IDE 可以幫助解決這個問題: Refactor > Migrate to AndroidX.

老的:

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'

新的:

implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM