API级别24以下=>错误膨胀类android.support.design.widget.FloatingActionButton

问题描述 投票:-2回答:1

当我在API级别24下运行我的代码时,我收到此异常。

致命异常:主要进程:com.example.scanwithanimations,PID:13393 java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.scanwithanimations / com.example.scanwithanimations.MainActivity}:android.view.InflateException:Binary XML文件行#14:错误类膨胀

android.support.design.widget.FloatingActionButton

我的main.xml如下。

<?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:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingTop="16dp">

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginRight="16dp"
    android:layout_marginBottom="164dp"
    android:src="@drawable/ic_action_wifi"
    android:elevation="6dp"
    android:id="@+id/fabwifi"
    app:pressedTranslationZ="12dp"
    android:backgroundTint="@color/fab1"
    android:visibility="invisible"
    />

</android.support.design.widget.CoordinatorLayout>
android android-layout floating-action-button
1个回答
2
投票

用这个

  • app:elevation="6dp"
  • app:backgroundTint="@color/fab1"

而不是这个

  • android:elevation="6dp"
  • android:backgroundTint="@color/fab2"

示例代码

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_marginRight="16dp"
    android:layout_marginBottom="164dp"
    android:src="@drawable/ic_action_wifi"
    app:elevation="6dp"
    android:id="@+id/fabwifi"
    app:pressedTranslationZ="12dp"
    app:backgroundTint="@color/fab1"
    android:visibility="invisible"
    />
© www.soinside.com 2019 - 2024. All rights reserved.