TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
int mGalleryItemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
ImageView image = (ImageView)findViewById(R.id.imageview);
image.setBackgroundResource(mGalleryItemBackground);
<resources>
<!-- These are the attributes that we want to retrieve from the theme
in view/Gallery1.java -->
<declare-styleable name="Gallery1">
<attr name="android:galleryItemBackground" />
</declare-styleable>
</resources>