android – FloatingActionButton类无法实例化

前端之家收集整理的这篇文章主要介绍了android – FloatingActionButton类无法实例化前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在查看材料设计中的新方法后,我尝试在应用程序中实现浮动操作按钮.但是,我在预览中收到此错误(预览 Android版本21):
The following classes could not be instantiated:
-android.support.design.widget.FloatingActionButton
(First paragraph of error)
java.lang.NullPointerException
at android.support.v4.graphics.drawable.DrawableCompatLollipop.setTintList(DrawableCompatLollipop.java:56)
at android.support.v4.graphics.drawable.DrawableCompat$LollipopDrawableImpl.setTintList(DrawableCompat.java:145)
at android.support.v4.graphics.drawable.DrawableCompat.setTintList(DrawableCompat.java:270)
etc...

任何人都有想法?这是我的build.gradle:

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
classpath 'com.android.tools.build:gradle:1.2.3'


defaultConfig {
    applicationId "owensetiawan.tutorials.fab"
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs',include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:design:22.2.0'
}

如果有人可以帮助我解释我的问题,这绝对是太棒了.

解决方法

嘿,我遇到了与实例化的设计库相同的问题,并解决了这一点

步骤1>晶圆代码

<android.support.design.widget.FloatingActionButton
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="bottom"
      android:clickable="true"
      android:src="@drawable/search"
      app:backgroundTint="@color/color_fav"
      app:borderWidth="0dp"
      android:layout_alignParentBottom="true"
      android:layout_alignParentEnd="true"
      />

步骤2>依赖

compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:recyclerview-v7:22.2.1'
    compile 'com.android.support:design:22.2.1'
    compile "com.android.support:support-v4:22.2.1"

步骤3>上述问题的主要步骤

容易的一个: – 去你的xml并点击预览,并在预览中的栏选择AP1 21

猜你在找的Android相关文章