Reputation: 21
I'm trying to setBackgroundResource
for an ImageView
, but it doesn't work.
Xml:
<ImageView
android:id="@+id/img_index"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="4dp"
android:background="@drawable/homegray"
android:gravity="center_horizontal|center_horizontal"
android:paddingBottom="4dp"
/>
Activity code:
imgIndex = (ImageView) this.findViewById(R.id.img_index);
imgIndex.setBackgroundResource(R.drawable.homewhite);
How can I control my ImageView
?
Upvotes: 0
Views: 4077
Reputation: 15740
Try this.
imgIndex = (ImageView) findViewById(R.id.img_index);
imgIndex.setImageResource(R.drawable.homewhite);
or
imgIndex = (ImageView) findViewById(R.id.img_index);
imgIndex.setImageDrawable(getResources().getDrawable(R.drawable.homewhite));
Upvotes: 4