【问题标题】:Floating Action Button could not be instantiated / Error inflating无法实例化浮动操作按钮/错误膨胀
【发布时间】:2016-05-17 16:44:19
【问题描述】:

我一直在扯头发;这工作得很好(好吧..几乎,没有正确浮动),然后在我添加android:backgroundTint="@color/fab"后不久它突然停止了,因为最小的SDK是19。

要尝试修复它,我有:

  • 更新了 Android Studio / SDK
  • 使缓存失效/重启
  • 重建项目
  • 确认targetSdkVersion 23
  • 确认compile 'com.android.support:design:23.1.1'
  • 确认classpath 'com.android.tools.build:gradle:1.5.0'
  • 确认<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

快到凌晨 5 点了,如果这很明显,我很抱歉,但我不知道还能尝试什么。 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/com.whereintheworld.com"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <LinearLayout android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <ListView xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/tracking_task_list"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </LinearLayout>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="16dp"
            android:clickable="true"
            android:src="@drawable/fab_ic_add"
            android:backgroundTint="@color/fab"
            app:layout_anchor="@id/tracking_task_list"
            app:layout_anchorGravity="bottom|right|end" />

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

</RelativeLayout>

【问题讨论】:

    标签: xml android-studio gradle floating-action-button


    【解决方案1】:

    com.android.support:appcompat-v7:21+ 增加了对在运行 preandroid 5.1 (API Level 21) 的设备上着色小部件的支持。要使用它,请确保扩展或设置 AppCompat 主题 并使用 app:backgroundTint 而不是 android:backgroundTint

    例子:

    <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/icon"
        app:backgroundTint="@color/accent"
        app:borderWidth="0dp" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-26
      • 1970-01-01
      相关资源
      最近更新 更多