I cannot seem to change the background image of my image button. Heres the code i'm currently trying to use:
ImageButton imgButton = (ImageButton) findViewById(R.id.showSportsButton);
imgButton.setBackgroundResource(R.drawable.tab2_selected);
However this seem to be placing the new image on top of the old image leaving me with 2 images overlapping each other.
Does anyone know why this is??
Use this method:
Make sure you are on same activity. If you are changing background of different activity first create the constructor then use object to change button.
and also check that
oncreate()
method hasvoid
return type if you are using onlyfindviewbyid
.in xml file,
<Button>
write:android:backgroud="@drawable/your_file"
For solving this question you should implement