How to change progress bar's progress color in Android

前端 未结 30 2326
情话喂你
情话喂你 2020-11-22 07:49

I\'m using an horizontal progress bar in my Android application, and I want to change its progress color (which is Yellow by default). How can I do it using code

30条回答
  •  [愿得一人]
    2020-11-22 08:16

    For my indeterminate progressbar (spinner) I just set a color filter on the drawable. Works great and just one line.

    Example where setting color to red:

    ProgressBar spinner = new android.widget.ProgressBar(
                    context,
                    null,
                    android.R.attr.progressBarStyle);
    
    spinner.getIndeterminateDrawable().setColorFilter(0xFFFF0000, android.graphics.PorterDuff.Mode.MULTIPLY);
    

    enter image description here

提交回复
热议问题