Android fab icon无法找到类'android.graphics.drawable.RippleDrawable'

时间:2017-02-10 19:34:18

标签: android android-activity android-support-library floating-action-button

在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

活动的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>

2 个答案:

答案 0 :(得分:0)

尝试在build.gradle(Module:app)文件defaultConfig部分添加multiDexEnabled true并重建项目。

答案 1 :(得分:0)

也许你用android studio资产图像工具插入mdpi hdpi xxdpi ..图标.. 这是我的问题