How to change progress bar's progress color in Android

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

    You can try to change your Styles, Themes, or using android:indeterminateTint="@color/yourColor" anywhere you want, but there's just one way o doing that will work on any Android SKD version:

    If you progress bar is not indeterminate, please use:

    progressBar.getProgressDrawable().setColorFilter(ContextCompat.getColor(context, R.color.yourColor), PorterDuff.Mode.SRC_IN );
    

    If you progress bar is indeterminate, please use:

    progressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(getContext(), R.color.yourColor), PorterDuff.Mode.SRC_IN );
    

    It's sad that Android is such a mess!

提交回复
热议问题