Android - Tinting ProgressBar on pre-Lollipop devices

后端 未结 6 637
梦谈多话
梦谈多话 2020-12-31 05:27

My app\'s minimum API-level is 19 (KitKat), and contains a layout with a horizontal ProgressBar. I\'m using android:progressTint attribute to tint

6条回答
  •  温柔的废话
    2020-12-31 05:53

    Thanks for the suggestions from everyone! :)

    The solution which works for me is to create a custom drawable XML file with the root element. There, I'm defining two layer items with the native Android IDs @android:id/background and @android:id/progress. After this, I can define the shapes and color resources I would like to use. This solution is similar to a more popular answer on this SO question.


    Content of my res/drawable/progressbar.xml file:

    
    
        
    
            
    
                 
    
                
    
            
    
        
    
        
    
            
    
                
    
                     
    
                    
    
                
    
            
    
        
    
    
    

    Defined as progressDrawable for my ProgressBar in the layout XML file:

    
    

    I didn't have a chance to test it below API 19, but on this level and above it works perfectly.

提交回复
热议问题