Android Imagebutton change Image OnClick

前端 未结 7 1113
心在旅途
心在旅途 2020-12-09 07:43

I just added a new drawable folder under res folder. In the drawable folder, i copied the ic_launcher.png file from

7条回答
  •  既然无缘
    2020-12-09 08:10

    This misled me a bit - it should be setImageResource instead of setBackgroundResource :) !!

    The following works fine :

    ImageButton btn = (ImageButton)findViewById(R.id.imageButton1);       
     btn.setImageResource(R.drawable.actions_record);
    

    while when using the setBackgroundResource the actual imagebutton's image stays while the background image is changed which leads to a ugly looking imageButton object

    Thanks.

提交回复
热议问题