How to change progress bar's progress color in Android

前端 未结 30 1986
情话喂你
情话喂你 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:22

    Use the android.support.v4.graphics.drawable.DrawableCompat:

                Drawable progressDrawable = progressBar.getIndeterminateDrawable();
                if (progressDrawable  != null) {
                    Drawable mutateDrawable = progressDrawable.mutate();
                    DrawableCompat.setTint(mutateDrawable, primaryColor);
                    progressBar.setProgressDrawable(mutateDrawable);
                }
    

提交回复
热议问题