我在这个 XML 中有一个可绘制对象:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:endColor="@color/transparent"
android:gradientRadius="200dp"
android:startColor="?attr/primaryDarkTransparent"
android:type="radial" />
</shape>
Run Code Online (Sandbox Code Playgroud)
startColor当使用以下内容时,XML 会导致崩溃?attr/primaryDarkTransparent:
Caused by: java.lang.RuntimeException: org.xmlpull.v1.XmlPullParserException: <internal><gradient> tag requires 'gradientRadius' attribute with radial type
Caused by: org.xmlpull.v1.XmlPullParserException: <internal><gradient> tag requires 'gradientRadius' attribute with radial type
attr戏剧性的故事是,当我使用insolid和时它运行得很好stroke,但我不知道 到底发生了什么gradient。
任何建议将不胜感激。
你的有两个问题shape。
在 Android L (API 21) 以下,您无法在自定义可绘制对象中使用属性,因此您应该替换?attr/primaryDarkTransparent为color引用。
应该gradientRadius是一个float. 例如200
| 归档时间: |
|
| 查看次数: |
1064 次 |
| 最近记录: |