首先定义布局文件如下
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/swipe_container"
>
</android.support.v4.widget.SwipeRefreshLayout>
然后在activity对改该布局文件进行处理
private SwipeRefreshLayout swipeLayout;
swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
swipeLayout.setOnRefreshListener(this);
swipeLayout.setColorScheme(android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
重写onRefresh()方法
@Override
public void onRefresh() {
// TODO Auto-generated method stub
Toast.makeText(MainUI.this, "刷新成功",Toast.LENGTH_SHORT)
.show();
}
类似效果如下: