Is there a way to set drawable's Alpha using XML?

后端 未结 9 873
无人及你
无人及你 2020-12-24 05:21

Easy like itself . I wanna make an alpha button , which would have a selected drawable this way:




        
9条回答
  •  萌比男神i
    2020-12-24 05:26

    My goal was to make a button have it's selected and pressed states at a different alpha - but using the same (png) resource and affecting as few files as possible.

    My solution is similar to altering the alpha in a BitmapDrawable - but it does it from the selector so only one file is affected.

    Use the tint function of Bitmap, remember that the tint will color the existing pixels so use a white color. Eg, #80FFFFFF - to keep color as original but reduce alpha by 50% This could also be used to change color of the icon when pressed.

    This is my drawable XML file:

    
    
        
            
            
        
        
            
            
        
        
            
            
        
    
    

提交回复
热议问题