2016-12-30 5 views
0

Ich benutze FAB (Floating Action Button) in der App, aber es macht mir das Leben schwer von den letzten Tagen. Jedes Mal, wenn ich neues Projekt mit einzelner Aktivität FAB Arbeit richtig zu erstellen, aber wenn ich neue Aktivitäten hinzufügen, beginnt es gab mir AusnahmeWie zu entfernen Floating-Action-Button Aufblasen Ausnahme in Android?

android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.floating action button. 

Mein XML-Code ist unten angegeben:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

    <include 
     layout="@layout/app_bar_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/nav_header_main" 
     app:menu="@menu/activity_main_drawer" /> 

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

Ich verwende AppCompat Thema auch und versucht alles außer problem bleiben gleich.

Folgende ist meine XML-Datei für FAB

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.vote3d.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     > 

     <android.support.v7.widget.Toolbar 
      xmlns:local="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="@color/colorAccent" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      local:navigationIcon="@mipmap/ic_menu_36dp"> 

      <ImageView 
       android:id="@+id/iv_toolbar_title" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:layout_marginRight="50dp" 
       android:src="@drawable/logo"/> 

      </android.support.v7.widget.Toolbar> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" 
      app:tabGravity="fill" 
      android:background="#e00000" 
      app:tabIndicatorColor="@android:color/white" 
      app:tabMode="fixed" 
      app:tabSelectedTextColor="@android:color/white" /> 

    </android.support.design.widget.AppBarLayout> 

    <!-- <include layout="@layout/content_main" />--> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/view_pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     android:background="#ffffff"/> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="30dp" 
     android:layout_height="30dp" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" /> 

</android.support.design.widget.CoordinatorLayout> 

ist nach dem Code, den ich für FAB in der Klasse bin mit

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
    fab.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
        .setAction("Action", null).show(); 
     } 
    }); 
+0

wo ist 'FloatingActionButton' Code ?? – Ironman

+0

Ich habe die Frage aktualisiert, bitte überprüfen Sie es jetzt –

Antwort

0

Verwendung Im Folgenden Code für Floation Aktionstaste in der XML-
und zugehörige Änderungen vornehmen

<android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@android:drawable/ic_dialog_email" /> 

wenn noch wird es den gleichen Fehler gibt bitte Activity-Datei und gradle Datei

+0

Danke Yogesh, aber ich habe das schon benutzt –

0

siehe this liefern. Vielleicht haben Sie etwas verpasst haben

0

Haben Sie Ihre build.gradle compile 'com.android.support:design:25.1.0' hinzugefügt?

Verwandte Themen