涟漪可绘制工具使Android API 19上的应用程序崩溃

涟漪可绘制工具使Android API 19上的应用程序崩溃

问题描述:

我正在使用自定义涟漪图 drawable

I am using a custom ripple drawable

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:exitFadeDuration="@android:integer/config_shortAnimTime"
    android:color="@android:color/white">

   <item android:id="@android:id/mask">
        <shape android:shape="rectangle" >
            <solid android:color="@android:color/white" />
        </shape>
   </item>


</ripple>

但它会使应用程序在API 19上崩溃

but it crashes the app on API 19

android.content.res.Resources$NotFoundException: File res / drawable /
    ripple_effect_square2.xml from drawable resource ID #0x7f02017d
at android.content.res.Resources.loadDrawable(Resources.java:2101)
at android.content.res.Resources.getDrawable(Resources.java:700)
at android.view.View.setBackgroundResource(View.java:15303)

Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line # 2: invalid drawable tag ripple
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java: 933)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java: 877)
at android.content.res.Resources.loadDrawable(Resources.java: 2097)
at android.content.res.Resources.getDrawable(Resources.java: 700) 
at android.view.View.setBackgroundResource(View.java: 15303) 

我应该怎么做以防止崩溃i ng?

What should i do to prevent crashing ?

RippleDrawable 已在API 21中添加,因此在早期的SDK中不可用。

The RippleDrawable was added in API 21, so it's not available on earlier SDKs.

您可以移动可绘制对象文件保存到 res / drawable-v21 ,以确保它在早期版本中不会崩溃。

You can move your drawable file to res/drawable-v21 to ensure it doesn't crash on earlier releases.