2016-05-14 4 views
0

Я хочу использовать FloatingActionButton в фрагменте. Но я получаю некоторые ошибки. Подумайте об этом из-за фрагмента. Как это решить?FloatingActionButton in Fragment

Фрагмент 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') 

} 

И ошибка:

Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class android.support.design.widget.FloatingActionButton

ответ

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" /> 
+0

Множественные корневые теги –

+0

возможно опубликовать полный XML, чтобы посмотреть –

0

добавить эту библиотеку в ваших dependicies:

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

не работает. Результат же –