使用
布局
下拉刷新view布局—可以將recycleview包進去
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
設置下拉刷新監聽
//找到控件
//設置下拉刷新監聽
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
//下拉刷新的邏輯:
list.clear();
loadData();
}
});
下拉刷新圈--將下拉刷新返回去
//讓下拉刷新的狀態消失
refreshLayout.setRefreshing(false);
下拉刷新圈的設置
//設置圈圈的顏色 參1可變參數--一個顏色顯示1s
refreshLayout.setColorSchemeColors(Color.RED, Color.BLUE, Color.GREEN);
//設置全的背景
//refreshLayout.setProgressBackgroundColorSchemeColor(Color.BLUE);