Change progressbar color through CODE ONLY in Android

前端 未结 12 1821
北海茫月
北海茫月 2020-12-01 01:12

I have a progressBar using the ProgressBar class.

Just doing this:

progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizont         


        
12条回答
  •  旧时难觅i
    2020-12-01 01:47

    I have given default color in xml by drawable.

    I have changed it programatically.

    activity_splasg.xml:

    
    

    splash_progress_drawable.xml:

    
    
        
            
                
            
        
    
        
            
                
                    
                
            
        
    
    
    

    Now How to change ProgressDrawable color programatically.

    ProgressBar splashProgressBar = (ProgressBar)findViewById(R.id.splashProgressBar);
    
    Drawable bgDrawable = splashProgressBar.getProgressDrawable();
    bgDrawable.setColorFilter(Color.BLUE, android.graphics.PorterDuff.Mode.MULTIPLY);
    splashProgressBar.setProgressDrawable(bgDrawable);
    

    Hope this will help you.

提交回复
热议问题