Skip to content Skip to sidebar Skip to footer

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.showSportsButto

Solution 1:

For solving this question you should implement

imgButton.setImageResource(R.drawable. tab2_selected);

Solution 2:

Use this method:

imgButon.setBackground(getActivity().getDrawable(R.drawable.your_icon));

Solution 3:

in xml file, <Button> write: android:backgroud="@drawable/your_file"

Solution 4:

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.

Activity obj= newactivity();
obj.imgButton.setBackgroundResource(R.drawable.tab2_selected);

and also check that oncreate() method has void return type if you are using only findviewbyid.

Post a Comment for "Android Change Image Button Background"