How to create a floating action button (FAB) in android, using AppCompat v21?

前端 未结 7 997
眼角桃花
眼角桃花 2020-11-30 18:03

I would like to create a floating action button (to add items to a listview), like google calendar, maintaining compatibility with pre-lollipop Android versions (before 5.0)

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 18:48

    I've generally used xml drawables to create shadow/elevation on a pre-lollipop widget. Here, for example, is an xml drawable that can be used on pre-lollipop devices to simulate the floating action button's elevation.

    
    
    
        
            
                
                    
                    
                
            
            
                
                    
                    
                
            
            
                
                    
                    
                
            
            
                
                    
                    
                
            
            
                
                    
                    
                
            
            
                
                    
                    
                
            
            
                
                    
                    
                
            
            
                
                    
                    
                
            
            
                
                    
                    
                
            
            
                
                    
                    
                
            
        
    
    
        
            
        
    
    
    

    In place of ?attr/colorPrimary you can choose any color. Here's a screenshot of the result:

    enter image description here

提交回复
热议问题