Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

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?

like image 797
irudaya rajasekar Avatar asked Sep 08 '15 14:09

irudaya rajasekar


People also ask

How do I change my swipe color to refresh?

The way to achieve that is by using setColorScheme in the Swipe Refresh object. It allows you to set 4 colors.

How do you swipe to refresh on Android?

To add the swipe to refresh widget to an existing app, add SwipeRefreshLayout as the parent of a single ListView or GridView . Remember that SwipeRefreshLayout only supports a single ListView or GridView child. You can also use the SwipeRefreshLayout widget with a ListFragment .

What is swipe refresh layout?

Android SwipeRefreshLayout is a ViewGroup that can hold only one scrollable child. It can be either a ScrollView, ListView or RecyclerView. The basic need for a SwipeRefreshLayout is to allow the users to refresh the screen manually. This is pretty common in the Facebook Newsfeed screen.


2 Answers

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.

like image 176
Ed George Avatar answered Oct 05 '22 19:10

Ed George


Change colors as per UI requirement:

swipeRefreshLayout.setColorSchemeColors(Color.BLUE, Color.YELLOW, Color.BLUE); 
like image 34
Hitesh Sahu Avatar answered Oct 05 '22 19:10

Hitesh Sahu