Android: change button background programmatically

前端 未结 3 907
醉酒成梦
醉酒成梦 2021-01-14 00:47

I have this resource file for colors


    #00f
    #f00         


        
3条回答
  •  醉梦人生
    2021-01-14 01:28

    You could use an xml file like one below, to create states for your button.

    The info about attributes available is here. You simply copy this xml file to your drawables folder in your project, name it for example custom_button.xml, and reference it in your layout with

    android:background="@drawable/custom_button"

    Here is xml file...

    
    
    
    
        
            
            
        
    
    
    
        
            
            
            
            
        
    
    
            
        
            
            
            
        
    
    

提交回复
热议问题