Android Swipe Down to Refresh Layout Example

Swipe to refresh is one of the important user interface pattern in android. Swipe down to refresh can easily be implemented/enabled in android application by adding the SwipeRefreshLayout widget in your XML layout file. SwipeRefreshLayout layout is used with the parent of a ListView, GridView, ScrollView and with other android layout and widgets. In this tutorial, you will learn to implement/enable swipe down to refresh activity in your android app and add different colors to the loader.

When users swipe down the screen or activity there will appear a circular loader/progress at the top of the activity/screen. The loader color is changed in each time which is under material design. Swipe to refresh or refresh functionality is mainly used in news application, social app, forums app etc.

Material Design Loader Examples for Android with Source Code
Material Design Horizontal ProgressBar Android Example
Android ListView with Image and Text

Android Example: How to Implement Swipe to Refresh in Android

To implement swipe to refresh in android app first of all open your app XML layout file and add SwipeRefreshLayout as GroupView using v4 design support library. Inside SwipeRefreshLayout widget add a LinearLayout inside ScvtollView. Your app content goes inside LinearLayout. If you want to use refresh functionality in your app with ListView or GridView you can add directly inside SwipeRefreshLayout widget. Following is the complete content of XML layout file.


Now, open your java activity file and implement setOnRefreshListener and setColorSchemeResources to SwipeRefreshLayout. In setColorSchemeResources add different colors which are displayed in circular ring of refresh progress bar. Following is the complete code of java activity file.


Following is the content of colors.xml and styles.xml file.



Android Example: How to Implement Swipe to Refresh in Android

You have done all things. Now run your Android Swipe Down to Refresh Layout Example application and swipe down the screen, there will appear a circular loader and the color of loader is changed. This swipe down to refresh app will look like above screenshot.
XML 4876863822292968015
Home item