You need to use a Theme.AppCompat theme (or descendant) with the design library

今天遇到一个奇葩的问题,在使用android design控件FloatingActionButton的时候报错了,报错内容如下:

Caused by: 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:164)

        at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:158)

我明明导入了com.android.support:design:27.1.1这个包,但还是不行,如下


最后终于找到了解决方案:

在清单文件AndroidManifest.xml中将application的theme改成@style/Theme.AppCompat.Light.NoActionBar就可以了;

如图  


猜你喜欢

转载自blog.csdn.net/jie1123161402/article/details/80591143