In ImageButton I want to remove the standard button background image. In http://developer.android.com it is said, that one must define his\her own background image or set the background color to be transparent. I tried to set a black background, but it didn't make any effect...
            Asked
            
        
        
            Active
            
        
            Viewed 5.8k times
        
    87
            
            
        11 Answers
41
            
            
        The best choice is not set a transparent background to your ImageButton. 
Give to your user a feedback when the button is tapped.
android:background="?attr/selectableItemBackgroundBorderless"
 
    
    
        Yury Fedorov
        
- 14,508
- 6
- 50
- 66
 
    
    
        Filipe Brito
        
- 5,329
- 5
- 32
- 42
- 
                    4Superb Solution. this answer should be marked as right. – Vasudev Vyas May 16 '19 at 10:10
24
            
            
        ImageButton.setBackgroundResource(0)
 
    
    
        Peter
        
- 2,480
- 6
- 39
- 60
- 
                    Excellent! This is the solution for programmatically doing Mudassir's solution. Thank you! – SMBiggs Dec 09 '11 at 16:43
- 
                    3It's setBackgroundResource, not setBackgroundResources. Use it like this : ((ImageButton) findViewById(R.id.my_button)).setBackgroundResource(0); – Quentin S. Feb 07 '14 at 21:37
8
            
            
        use the following property in your in the xml of ImageButton:
android:background="@drawable/icon"
where icon is the name of the image kept in your drawable.
 
    
    
        Dinesh Sharma
        
- 11,533
- 7
- 42
- 60
- 
                    1This is a cleaner solution than setting the `src` and nulling out the background. – Christopher Pickslay Nov 08 '14 at 00:09
5
            
            
        No, it has to be transparent, not black. Try color: #00FFFFFF
 
    
    
        Zsombor Erdődy-Nagy
        
- 16,864
- 16
- 76
- 101
2
            
            
        Dot't use button.setBackgroundResource(0);
on some devices you will get:  
android.content.res.Resources$NotFoundException: Resource ID #0x0
Better use button.setBackgroundColor(Color.TRANSPARENT);
 
    
    
        SpyZip
        
- 5,511
- 4
- 32
- 53
0
            
            
        Using Kotlin, you can do this:
val myImageButton = ImageButton(context).apply({
    background = null
    // and if you need to add drawable, simply use:
    setImageDrawable(ContextCompat.getDrawable(context, 
                         R.drawable.ic_save_black_24px))
})
 
    
    
        Hasan A Yousef
        
- 22,789
- 24
- 132
- 203
0
            
            
        In the latest android version, the background image doesn't remove even when you set android:background="@null".
Setting android:minHeight="0dp" works for me.
 
    
    
        Neela
        
- 1,328
- 4
- 23
- 45
 
     
     
     
    