【发布时间】:2023-03-27 22:07:01
【问题描述】:
我创建了一个自定义类,它扩展了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。那么有什么问题呢?
谢谢。
【问题讨论】:
-
您的主要活动是否扩展了 AppCompat?
-
@JuliánMartínez 不,MainActivty 扩展了 AppCompatActivity。
标签: android floating-action-button