首先布局:

<?xml version="1.0" encoding="utf-8"?>xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:layout_width="match_parent"    android:id="@+id/refresh"    android:layout_height="match_parent"    >            android:layout_width="wrap_content"        android:layout_height="wrap_content">                            android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="我是系统自带的下拉刷新控件"                android:gravity="center"/>         
Activity中调用

public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {    private SwipeRefreshLayout refresh;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        refresh = (SwipeRefreshLayout) findViewById(R.id.refresh);        //设置下拉刷新的箭头颜色        refresh.setColorSchemeResources(android.R.color.holo_red_light);        //设置下拉刷新的背景颜色为白色        refresh.setProgressBackgroundColorSchemeResource(android.R.color.white);        refresh.setOnRefreshListener(this);        refresh.setOnRefreshListener(this);    }    @Override    public void onRefresh() {        Toast.makeText(this, "下拉刷新成功", Toast.LENGTH_SHORT).show();        if (refresh.isRefreshing()) {//如果正在刷新            refresh.setRefreshing(false);//取消刷新        }    }}


更多相关文章

  1. android SpannableString使用详解
  2. android SwipeRefreshLayout 下拉刷新控件使用
  3. Android下拉刷新,上拉加载
  4. Android中颜色透明度对应16进制值
  5. Android(安卓)搜索到的关键字改变颜色
  6. android ActionBar的使用
  7. android 如何从sqlite读取数据到spinner下拉中显示
  8. android 按钮按下时改变字体颜色
  9. Android(安卓)常用的ui(单选框 多选框 下拉列表框 拖动条)

随机推荐

  1. Android腾讯微薄客户端开发十四:首页menu
  2. Android(安卓)使用HTTP(get和post)方式登陆
  3. android上下文 判断两个context是否相同
  4. 对比onSaveInstanceState和onRestoreInst
  5. Android中的通知Notification
  6. Android(安卓)效果
  7. android下无预览摄像
  8. android自动更新软件版本
  9. Android(安卓)实现apk文件下载并自动安装
  10. Android(安卓)自定义相机