Change progressbar color through CODE ONLY in Android

前端 未结 12 1822
北海茫月
北海茫月 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条回答
  •  情书的邮戳
    2020-12-01 02:02

    Update

    In newer versions of Android (21 works), you can change the color of a progressbar programmatically by just using setProgressTintList.

    To set it red, use:

    //bar is a ProgressBar
    bar.setProgressTintList(ColorStateList.valueOf(Color.RED));
    

提交回复
热议问题