Android 自定义类扩展FloatingActionButton时出错

Android 自定义类扩展FloatingActionButton时出错,android,floating-action-button,Android,Floating Action Button,我创建了一个自定义类,它扩展了FloatingActionButton public class customFAB extends FloatingActionButton { public customFAB(Context context) { super(context); } } 我从MainActivity中调用这个类 customFAB cFab = new customFAB(getApplicationContext); 但是我得到了

我创建了一个自定义类,它扩展了
FloatingActionButton

public class customFAB extends FloatingActionButton
{
    public customFAB(Context context)
    {
        super(context);
    }
}
我从MainActivity中调用这个类

customFAB cFab = new customFAB(getApplicationContext);
但是我得到了这个错误

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

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>

@颜色/原色
@颜色/原色暗
@颜色/颜色重音
假的
真的
主题是
theme.AppCompat
。那么问题是什么呢


谢谢。

您的
应用程序的
上下文将不会有主题,尽管您可以使用清单中
元素的
主题
属性设置应用程序的默认主题。在实例化类似的
视图时,您需要使用
活动
上下文

例如:

customFAB cFab = new customFAB(MainActivity.this);

您的
应用程序的
上下文将不会有主题,尽管您可以使用清单中
元素的
主题
属性设置应用程序的默认主题。在实例化类似的
视图时,您需要使用
活动
上下文

例如:

customFAB cFab = new customFAB(MainActivity.this);

您的主要活动是否扩展AppCompat?@JuliánMartínez否,主活动是否扩展AppCompat活动。您的主要活动是否扩展AppCompat?@JuliánMartínez否,主活动是否扩展AppCompat活动。