Android L's Ripple Effect - Touch Feedback for Buttons - Using XML

前端 未结 7 1676
青春惊慌失措
青春惊慌失措 2020-11-27 11:13

I am trying to understand how to implement the \"Ripple Effect - Touch Feedback\" for buttons and other views. I looked at the questions related to Ripple touch effect on SO

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 11:49

    Slight addition to above answer: Note that the mask color is not used in any way.

    You can do more complicated things with ripple as well. For example, if you wanted a border on your ripple button you can use it like a layer-list.

    
    
        
        
            
                
                
            
        
    
        
        
            
                
                
                
            
        
     
    

    Note that the element with id @android:id/mask is only used to show where the ripple effect will stop at. If you wanted it to cover the whole button, you could change the android:shape to be rectangle. You can imagine doing many more interesting things with this as well!

    Also make sure to have a backup drawable for devices that aren't 21 yet or the app will crash on old devices.

提交回复
热议问题