我曾经在另一个项目中尝试使用fab实现悬浮操作按钮并进行自定义,它可以正常工作。但是这一次,在我的xml布局中创建fab对象时,它显示了错误。感到困惑后,我尝试移除其中的一些标签,并发现添加android:backgroundTint标签时会出现错误。
以下是代码:
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="mini"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/ic_action_fab"
android:backgroundTint="#2196F3"
android:layout_margin="12dp"/>
这是我用的构建:
compileSdkVersion 25
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.xxxx.xxxx"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "2.0.4"
}
我已经添加了谷歌设计Gradle。
错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxx.xxxx/com.xxxx.xxxx.HomeActivity}: android.view.InflateException: Binary XML file line #141: Binary XML file line #141: Error inflating class android.support.design.widget.FloatingActionButton
一旦我删除android:backgroundtint标签,错误就消失了。不知道为什么会出现这种情况?