Android xml格式的app:srcCompat的InflateException

Android xml格式的app:srcCompat的InflateException,android,xml,android-appcompat,Android,Xml,Android Appcompat,当在my.xml布局中使用app:srcCompat时,我无法在运行android 4.2.1的设备上运行代码。例如,我有一个这样的工厂: <android.support.design.widget.FloatingActionButton android:id="@+id/fab" ... android:tint="@color/colorWhite" app:backgroundTint="@color/colorPrimary" app:s

当在my.xml布局中使用app:srcCompat时,我无法在运行android 4.2.1的设备上运行代码。例如,我有一个这样的工厂:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    ...
    android:tint="@color/colorWhite"
    app:backgroundTint="@color/colorPrimary"
    app:srcCompat="@drawable/ic_add"/>
没有app:srcCompat行,它可以正常工作

在我的build.gradle中,我还有:

defaultConfig {
    vectorDrawables.useSupportLibrary = true
    ...
}

...

dependencies {
      ...
        compile "com.android.support:appcompat-v7:26.0.0-alpha1"
}
我错过了什么?如有任何想法/想法,将不胜感激

解决方案:
这个答案对我有用

您可能忘了添加设计支持库。因此,您应该通过添加以下行在依赖项中添加设计支持库:

dependencies {
      ...
  compile "com.android.support:design:27.0.0"
  //compile "com.android.support:appcompat-v7:26.0.0-alpha1"
}
您不需要添加appcompat库,因为它隐式包含在设计支持库中。请记住,不要在代码中使用alpha版本的库

有关设计支持库的更多信息,请访问


更新

添加以下内容:

试试这个

Android Api级别19或以下不支持矢量图像,我得到 这个解决方案

在此处设置小部件id并从中删除可绘制的矢量 小部件


谢谢你的建议!我已将支持设计库更新为27.0.0版。但问题仍然存在。@AlexKost:我已经更新了答案。添加矢量可绘制支持。Android Api级别19或以下版本不支持矢量图像“您可以使用VectorDrawableCompat返回Api级别7”,如下所述:
defaultConfig {
    vectorDrawables.useSupportLibrary = true
    ...
}

...

dependencies {
      ...
        compile "com.android.support:appcompat-v7:26.0.0-alpha1"
}
dependencies {
      ...
  compile "com.android.support:design:27.0.0"
  //compile "com.android.support:appcompat-v7:26.0.0-alpha1"
}
compile "com.android.support:support-vector-drawable:27.0.0"
private void setBackgrounds(){

        Drawable drawableLeft = AppCompatResources.getDrawable(modelet.getContext(), R.drawable.ic_local_taxi_black_16dp);
        modelet.setCompoundDrawablesWithIntrinsicBounds(drawableLeft, null, null, null);
}