So I am pretty new to android and I am trying to setup a floating action button with the Android Design Support Library using this guide in Android Studio.
My Projec
I have been facing this problem recently and tried to change dependencies version, invalidating caches and restart, etc. The preview rendered once and then reopening my xml file, it raised the same error.
Clicking on the refresh button at the preview window solved to me (momentarily) the problem, letting me see the layout and its elements properly.
If you are using androidx, you need to use:
implementation 'com.google.android.material:material:1.2.1'
(or whatever latest version you want).
The action button in the XML looks like:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/delete_buttom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_margin="20dp"
android:src="@drawable/ic_baseline_delete_24px" />
I had the same issue and updated the Android Support Repository", "Android Support Library"(22.2.1) and "Android SDK Tool"(24.1.2) using SDK manager now its working fine. Once update finish rebuild the project. For more https://developer.android.com/tools/support-library/setup.html
I had the same problem with Android Studio complaining that it couldn't instantiate FloatingActionButton. The "Exception Details" showed this:
java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:33)
at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:159)
at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:153)
Basically, I was using Material.Light as my theme, but I needed to use an AppCompat theme. I switched to AppCompat.Light and the problem was solved!
I had the same issue and could solve it this way : https://stackoverflow.com/a/59211828/12337593
You need the Library design, in the build.gradle
file add:
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:design:25.1.1'
Then Sync
the Gradle, build and Reresh