我试图?attr/selectableItemBackgroundBorderless
在 a 的XML定义中引用StateListDrawable
以更改原始中定义的某些状态的行为:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/transparent" android:state_pressed="false" />
<item android:drawable="?selectableItemBackgroundBorderless" />
</selector>
但这会导致崩溃:
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 0: TypedValue{t=0x2/d=0x7f040298 a=-1}
at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:946)
at android.content.res.TypedArray.getDrawable(TypedArray.java:930)
at android.graphics.drawable.StateListDrawable.inflateChildElements(StateListDrawable.java:177)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:122)
at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:142)
at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1332)
at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1291)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:833)
... 46 more
我不明白的是,为什么它实际上可以与LayerDrawable
似乎在代码方面做同样事情的 a 一起工作:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/transparent" />
<item android:drawable="?selectableItemBackgroundBorderless" />
</layer-list>
是否可以在 a 中使用?attr/
a <selector>
?