Android change theme of new ProgressBar()
-
23-12-2020 - |
Question
I want to change the theme of just ONE ProgressBar
so changing the global theme is not an option.
Existing code:
ProgressBar pb = new ProgressBar(context);
((LinearLayout) v).addView(pb,0);
It works, no errors, but uses the default them. How can I change that?
Solution
Use a different constructor to set the style:
ProgressBar loadingProgressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
And if you want to customize the actual appearance (colors, size, etc.) use this:
loadingProgressBar.setProgressDrawable(getResources().getDrawable(R.drawable.mycustomtheme));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow