Fragment中的FloatingActionButton

时间:2016-05-14 11:10:43

标签: java android

我想在Fragment中使用FloatingActionButton。但我得到一些错误。想想因为碎片。怎么解决这个问题?

片段xml

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/material_blue_grey_800">


    <ListView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/feedListView">

    </ListView>

    <android.support.design.widget.FloatingActionButton
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:src="@drawable/ic_home"
        app:backgroundTint="@color/floating_action_button_color"
        app:borderWidth="0dp" />

</android.support.v4.widget.SwipeRefreshLayout>

风格:

    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
    <item name="colorAccent">@color/tagWishes</item>
</style>

构建gradle文件:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    defaultConfig {
        applicationId "some.app"
        minSdkVersion 14
        targetSdkVersion 23
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    productFlavors {
    }
}

ext {
    supportLibVersion = '23.4.0'  // variable that can be referenced to keep support libs consistent
}

dependencies {

    compile 'com.beardedhen:androidbootstrap:2.2.0'
    compile "com.android.support:appcompat-v7:${supportLibVersion}"
    compile "com.android.support:design:${supportLibVersion}"

    compile 'se.simbio.encryption:library:1.2.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.github.ksoichiro:android-observablescrollview:1.5.2'
    compile files('libs/volley.jar')
    compile files('libs/httpclient-4.3.6.jar')
    compile files('libs/httpcore-4.3.3.jar')
    compile files('libs/httpmime-4.3.6.jar')

}

错误:

  

引起:android.view.InflateException:二进制XML文件行#15:   膨胀类时出错   android.support.design.widget.FloatingActionButton

2 个答案:

答案 0 :(得分:0)

将工厂移至SwipeRefreshLayout之外。 你能尝试那样:

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/material_blue_grey_800">

<ListView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/feedListView">
</ListView>

</android.support.v4.widget.SwipeRefreshLayout>

<android.support.design.widget.FloatingActionButton
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="16dp"
    android:src="@drawable/ic_home"
    app:backgroundTint="@color/floating_action_button_color"
    app:borderWidth="0dp" />

答案 1 :(得分:0)

将该库添加到您的依赖项:

 compile 'com.android.support:design:23.+'