我创建了一个自定义类并扩展了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.
my style.xml
is
<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
。那么问题出在哪里呢?
Thanks.
Your Application
's Context
尽管您可以使用以下命令设置应用程序的默认主题,但不会有主题theme
属性上的<application>
清单中的元素。您需要使用您的Activity
's Context
实例化时View
就这样。
例如:
customFAB cFab = new customFAB(MainActivity.this);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)