Gihan
Gihan

Reputation: 3799

How to Change the Color of a Custom Progress Bar Using Java Instead of XML?

I'm a beginner to Android and Java. I have some trouble setting this custom loading animation I found on GitHub. https://ybq.github.io/Android-SpinKit/.

I've implemented it directly in to my code using Java as below and it works.

progressBar = findViewById(R.id.progressBar);
Sprite threeBounce = new ThreeBounce();
progressBar.setIndeterminateDrawable(threeBounce);

But I want to change the color of it from code without using XML. Your help is greatly appreciated.

Upvotes: 1

Views: 328

Answers (1)

Rene Ferrari
Rene Ferrari

Reputation: 4216

Fortunately this Library offers a method called setColor.

You can use this code, the progressBar will be blue then:

SpinKitView progressBar = findViewById(R.id.progressBar);
Sprite threeBounce = new ThreeBounce();
threeBounce.setColor(Color.BLUE);
progressBar.setIndeterminateDrawable(threeBounce);

Upvotes: 1

Related Questions