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();
}
});
wo ist 'FloatingActionButton' Code ?? – Ironman
Ich habe die Frage aktualisiert, bitte überprüfen Sie es jetzt –