Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SwipeRefreshLayout refresh indicator not visible

I'm using the android.support.v4.widget.SwipeRefreshLayout inside of a fragment. The swipe works perfectly to refresh my data but all I can see is a blank white circle as a swipe indicator. All of the other questions I have seen about this do not seem to work.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_all_assets,container,false);
    mListView = (ListView) view.findViewById(R.id.listView);
    mSwipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container);
    mSwipeLayout.setColorSchemeColors(android.R.color.holo_blue_bright,
            android.R.color.holo_green_light,
            android.R.color.holo_orange_light,
            android.R.color.holo_red_light);
    return view;
}

XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">


<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/listView"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"/>

</android.support.v4.widget.SwipeRefreshLayout>

Dependencies

compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v13:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.+'
compile 'com.google.zxing:android-integration:3.1.0'

How can I get this refresh indicator to work?

like image 591
Nick H Avatar asked Oct 29 '14 21:10

Nick H


People also ask

How to disable Swipe to refresh Android?

To disable the gesture and progress animation, call setEnabled(false) on the view. This layout should be made the parent of the view that will be refreshed as a result of the gesture and can only support one direct child.

How to implement Swipe down to refresh in 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.


1 Answers

The problem is that setColorSchemeColors() expects color integers as inputs (e.g. Color.BLUE), not color resource IDs.

You should use setColorSchemeResources() instead, which accepts color resource references.

like image 104
Bryan Herbst Avatar answered Sep 27 '22 21:09

Bryan Herbst