カスタム属性 (@drawable) をカスタム ビューに追加しようとしていて、それを resourceId として取得したいと考えています。コードを介してアクセスしたい場合、どういうわけか私のビューはそれを見つけることができません:
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.TouchImageView, defStyle, 0);
int base = a.getResourceId(R.styleable.imageDrawable, R.drawable.kaart);
私が得たエラーは次のとおりです: 解決できないか、フィールドではありません
私のattrs.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="TouchImageView">
<attr name="imageDrawable" format="string"/>
</declare-styleable>
</resources>
レイアウトの xml は次のようになります。
<nl.raakict.android.util.TouchImageView
android:id="@+id/plattegrond"
android:layout_width="match_parent"
android:layout_height="match_parent"
imageDrawable="@drawable/kaart"/>