【问题标题】:Floating action button Error inflating class android.support.design.widget.FloatingActionButton When using in DrawerLayout浮动动作按钮错误膨胀类android.support.design.widget.FloatingActionButton在DrawerLayout中使用时
【发布时间】:2017-01-18 19:18:37
【问题描述】:

我目前使用 DrawerLayout 作为我的根布局来访问包含我的片段的滑动菜单。我想在所有片段中添加一个 FAB 但得到错误 -

android.view.InflateException:二进制 XML 文件第 21 行:二进制 XML 文件第 21 行:膨胀类错误 android.support.design.widget.FloatingActionButton

我尝试将它包含在 FrameLayout 中,但仍然出现相同的错误。我也尝试了多个图像,因为我知道当图像的像素多于应用程序的内存时,可能会发生此错误。我的目标 SDK 是 23,我已经编译了相关的 appcompat 库。

一些额外的信息;

主要活动 XML

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="com.example.liamk.version2.MainActivity"
    android:id="@+id/drawerLayout">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/main_fragment">

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/fab"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|right"
                android:layout_marginBottom="@dimen/activity_vertical_margin"
                android:layout_marginRight="@dimen/activity_horizontal_margin"
                android:src="@mipmap/ic_list_black_24dp"/>
        </FrameLayout>
    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/nav_menu"
        app:menu="@menu/navigation_menu"
        android:layout_gravity="start"
        app:headerLayout="@layout/navigationheader">

    </android.support.design.widget.NavigationView>
    </android.support.v4.widget.DrawerLayout>

分级

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.example.liamk.version2"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services-auth:10.0.1'
    compile 'pub.devrel:easypermissions:0.2.1'
    compile('com.google.api-client:google-api-client-android:1.22.0') {
        exclude group: 'org.apache.httpcomponents'
    }
    compile('com.google.apis:google-api-services-calendar:v3-rev225-1.22.0') {
        exclude group: 'org.apache.httpcomponents'
    }
}

主题

    <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>

【问题讨论】:

    标签: xml android-fragments inflate-exception floating-action-button


    【解决方案1】:

    我找到了一个我忘记发布的解决方法。

    在父协调器布局中使用标签布局作为子布局。材料设计是你的朋友。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-02
      • 2017-02-16
      • 1970-01-01
      • 1970-01-01
      • 2016-05-17
      • 2016-02-29
      • 1970-01-01
      相关资源
      最近更新 更多