Binary XML file line #8: Error inflating class android.support.design.widget.FloatingActionButton

本文针对使用DrawerLayout出现的错误提供了解决方案,包括确认引入support库、在style中添加相应theme以及确保activity使用正确的主题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在使用DrawerLayout的时候出现了这个错误,可以参考以下步骤进行检查
1.确认引入对应support库

compile 'com.android.support:design:22.2.0'//版本自己确定
compile 'com.android.support:appcompat-v7:22.2.0'//版本自己确定

2.确认style中添加了对应theme

<!-- 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>
<!-- DrawerLayout theme. -->
    <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" />

3.确保你的 activity extends AppCompatActivity 并且使用 Theme.AppCompat 主题. 由于 FloatingActionButton 需要引用 colorAccent 所以请确保在你的 theme 中已经定义colorAccent

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值