How can you change a Swipe refresh layout's color for each rotation?

Has anyone noticed the SwipeRefreshLayout in gmail. It changes color for every rotation in a single load iteration. Does anyone have any idea how to achieve it?


The documentation for SwipeRefreshLayout details the setColorSchemeResources() and setColorSchemeColors() methods that can be used to set the color scheme of your SwipeRefreshLayout

The docs state:

Set the color resources used in the progress animation from color resources. The first color will also be the color of the bar that grows in response to a user swipe gesture.

You should note that setColorSchemeColors() should be used with specific colour values and setColorSchemeResources() should be used when you intend to use resource references to colours (e.g. R.color.red).

Please also note that setColorScheme(), the old way of completing this, is now deprecated.


Change colors as per UI requirement:

swipeRefreshLayout.setColorSchemeColors(Color.BLUE, Color.YELLOW, Color.BLUE);

Here is how you can get the colors from the colors.xml resource and set them as SwipRefreshLayout's color scheme.

int c1 = getResources().getColor(R.color.refresh_progress_1);
int c2 = getResources().getColor(R.color.refresh_progress_2);
int c3 = getResources().getColor(R.color.refresh_progress_3);

mySwipeRefreshLayout.setColorSchemeColors(c1, c2, c3);

swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.simpleSwipeRefreshLayout);

swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener()
 {
            @Override
            public void onRefresh() {

                // implement Handler to wait for 3 seconds and then update UI means update value of TextView
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        // cancle the Visual indication of a refresh
                        swipeRefreshLayout.setRefreshing(false);
                        swipeRefreshLayout.setColorSchemeResources(R.color.Aqua,R.color.Blue,R.color.Violet);
                        // Generate a random integer number
                        Random r = new Random();
                        int i1 = r.nextInt(80 - 65) + 65;
                        // set the number value in TextView
                        textView.setText(String.valueOf(i1));
                    }
                }, 3000);
            }
        });
    }