gpt4 book ai didi

android - FloatingActionButton 类无法实例化

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:42:24 26 4
gpt4 key购买 nike

在了解了 Material Design 中的新方法后,我尝试在应用中实现一个 float 操作按钮。但是,我在预览(预览 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 步 > fab 代码

    <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"
/>

第二步>依赖

    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 - FloatingActionButton 类无法实例化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31319127/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com