I cannot seem to change the background image of my image button. Heres the code i\'m currently trying to use:
ImageButton imgButton = (ImageButton) findViewB
Use this method:
imgButon.setBackground(getActivity().getDrawable(R.drawable.your_icon));
in xml file, <Button>
write: android:backgroud="@drawable/your_file"
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= new activity();
obj.imgButton.setBackgroundResource(R.drawable.tab2_selected);
and also check that oncreate()
method has void
return type if you are using only findviewbyid
.
For solving this question you should implement
imgButton.setImageResource(R.drawable. tab2_selected);