Cannot setup floating action buttons as class cannot be found (Android Studio)

前端 未结 7 1271
情书的邮戳
情书的邮戳 2021-01-02 07:39

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

7条回答
  •  有刺的猬
    2021-01-02 08:01

    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.(FloatingActionButton.java:159)
        at android.support.design.widget.FloatingActionButton.(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!

提交回复
热议问题