Pra*_*nth 2 java android floating-action-button
我有一个充满自定义视图的应用程序.当我尝试以编程方式创建FAB时,它会抛出错误
引起:java.lang.IllegalArgumentException:您需要将Theme.AppCompat主题(或后代)与设计库一起使用.
这是我的代码.
private FloatingActionButton getFAB() {
FloatingActionButton fab = new FloatingActionButton(getContext());
fab.setBackgroundDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_add_white_24dp));
return fab;
}
Run Code Online (Sandbox Code Playgroud)
这是我的应用主题.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
Run Code Online (Sandbox Code Playgroud)
请帮我.
通过使用主题包装器修复.但是我仍然对使用ContextThemeWrapper感到惊讶
private FloatingActionButton getFAB() {
Context context = new android.support.v7.internal.view.ContextThemeWrapper(getContext(), R.style.AppTheme);
FloatingActionButton fab = new FloatingActionButton(context);
return fab;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4430 次 |
| 最近记录: |