how to change background image of button when clicked/focused?

后端 未结 8 1070
旧时难觅i
旧时难觅i 2020-11-30 01:00

I want to change the background image of a button when clicked or focused.

This is my code:

Button tiny = (Button)findViewById(R.id.tiny);
tiny.setOn         


        
8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 01:44

    Its very easy to implement . For that you need to create a one xml file(selector file) and put it in drawable folder in res. After that set xml file in button's background in your layout file.

    button_background_selector.xml

    
    
        
        
        
        
    
    

    Now set the above file in button's background.

提交回复
热议问题