Why is my design screen gray and only says "androidx.constraintlayout.ConstraintLayout" in Android Studio?

Viewed 1845

I'm trying to follow a playlist on YouTube by CodingInFlow for Android Studio development.

I'm trying to follow this video, but I'm having a problem... https://www.youtube.com/watch?v=-sPOtGqd5OA&list=PLrnPJCHvNZuBtcos16XJnfFx2fSUOyW_-&index=9

My design-screen is just showing as a gray box and I get the error that the "androidx.constraintlayout.ConstraintLayout (class couldn't be found)."

See code and example image here: https://i.imgur.com/kub2gIH.png

In the videos he's not using AndroidX and his opening-tag is different to mine in his .xml files.

His opening tag for his .xml document: android.support.constraint.ConstraintLayout

My opening tag for my .xml document: androidx.constraintlayout.ConstraintLayout

How can I fix this so that the design will show up where the gray box currently is?

Thank you

2 Answers

It is perhaps your are missing the library of it and it's not recognized.

Open your build.gradle (app) and add :

  implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

The video is a bit old regarding the "androidx" library, so that's why he's tag is different than yours. So you will have to add the library which supports it.

Make sure you have migrated to androidx

https://developer.android.com/jetpack/androidx/migrate

add this line to build.gradle

dependencies {
    implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta4"
}

in your xml

<androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/constraintLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

</androidx.constraintlayout.widget.ConstraintLayout>
Related