Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android change image button background

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??

like image 761
Welton122 Avatar asked Dec 20 '22 00:12

Welton122


1 Answers

For solving this question you should implement

imgButton.setImageResource(R.drawable. tab2_selected);
like image 175
Oleg Gordiichuk Avatar answered Jan 08 '23 08:01

Oleg Gordiichuk