Android开发:FloatingActionButton与Snackbar导入错误求助
Hey there, I’ve dealt with this exact frustration before when setting up new Activities in Android projects—let’s get those import errors sorted out quickly!
Here are the most common fixes to try:
Update your Material Components dependency
Those widgets live in the Material Components library, not the old support libraries anymore. Open your module-levelbuild.gradlefile (the one inside your app folder), make sure you have this dependency added:implementation 'com.google.android.material:material:1.9.0' // Use the latest stable version availableClick the "Sync Now" prompt that pops up after saving the file to apply the change.
Replace outdated support imports with AndroidX
The oldandroid.support.design.widget.*packages are deprecated. Swap your erroring import lines with these AndroidX equivalents:import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar;Migrate your project to AndroidX (if needed)
If your Udacity project is still using the old support library ecosystem, it might clash with the new Material Components. Go toRefactor > Migrate to AndroidXin Android Studio—this tool will automatically update all your imports, dependencies, and resource files to use AndroidX standards.Clean and rebuild your project
Sometimes cached build files cause weird unresolved symbol errors. RunBuild > Clean Project, followed byBuild > Rebuild Project, then restart Android Studio to clear any lingering issues.
内容的提问来源于stack exchange,提问作者mcansado

