波纹绘制使应用程序在 Android API 19 上崩溃

2024-01-08

我正在使用自定义波纹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 上的应用程序崩溃

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) 

我应该怎么做才能防止崩溃?


The 波纹绘制 https://developer.android.com/reference/android/graphics/drawable/RippleDrawable.html是在 API 21 中添加的,因此它在早期的 SDK 中不可用。

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

波纹绘制使应用程序在 Android API 19 上崩溃 的相关文章

随机推荐