How to Customize a Progress Bar In Android

前端 未结 9 2413
鱼传尺愫
鱼传尺愫 2020-11-22 16:07

I am working on an app in which I want to show a ProgressBar, but I want to replace the default Android ProgressBar.

So how can I customize

9条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 16:34

    Customizing a ProgressBar requires defining the attribute or properties for the background and progress of your progress bar.

    Create an XML file named customprogressbar.xml in your res->drawable folder:

    custom_progressbar.xml

    
    
        
        
        
            
        
       
    
      
      
        
            
                
            
        
        
     
    

    Now you need to set the progressDrawable property in customprogressbar.xml (drawable)

    You can do this in the XML file or in the Activity (at run time).

    Do the following in your XML:

    
    

    At run time do the following

    // Get the Drawable custom_progressbar                     
        Drawable draw=res.getDrawable(R.drawable.custom_progressbar);
    // set the drawable as progress drawable
        progressBar.setProgressDrawable(draw);
    

    Edit: corrected xml layout

提交回复
热议问题