android change image button background

后端 未结 4 1461
我寻月下人不归
我寻月下人不归 2021-01-13 18:24

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         


        
4条回答
  •  猫巷女王i
    2021-01-13 18:36

    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.

提交回复
热议问题