【发布时间】:2017-06-29 06:28:34
【问题描述】:
在 Android 中,当我运行应用程序时会触发此错误:
Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
当我取消注释这些行时会触发错误:
fabAddLocation = (FloatingActionButton) findViewById(R.id.fab_add_location);
fabAddLocation.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
...
}
});
我认为这可能是兼容性问题。我使用以下支持库:
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:support-v4:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:recyclerview-v7:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
然后在模块 build.gradle 中进行配置:
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.mypackage.myproj"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
活动扩展了 AppCompatActivity
Activity的XML布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="....MainActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"
android:id="@+id/mapFragment" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="10dp"
android:src="@mipmap/ic_add_fab"
app:layout_anchor="@id/mapFragment"
android:id="@+id/fab_add_location"
app:layout_anchorGravity="bottom|left|end" />
</android.support.design.widget.CoordinatorLayout>
【问题讨论】:
-
请贴出定义或创建这个fab的xml布局文件。
-
@AnuragSingh 我用 XML 更新了问题
-
你能不能把 android:src="@mipmap/ic_add_fab" 改成 android:src="@drawable/some.png"。请告诉我会发生什么。
-
同样的事情我试图完全删除 src 图标并且发生同样的错误
标签: android android-activity android-support-library floating-action-button