Android 下拉刷新
以前旧版用的是开源的PullToRefresh第三方库,该库现在已经不再维护了:
chrisbanes/Android-PullToRefresh
https://github.com/chrisbanes/Android-PullToRefresh
使用PullToRefresh实现下拉刷新和上拉加载
http://blog.csdn.net/ueryueryuery/article/details/17440465
在support v4中google提供了SwipeRefreshLayout 来实现下拉刷新
SwipeRefreshLayout | Android Developers
https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html
说明: 在support v4兼容包下,但必须把你的support library的版本升级到19.1
Android SwipeRefreshLayout用法
http://stormzhang.com/android/2014/03/29/android-swiperefreshlayout/
http://www.cnblogs.com/JinyaoLi/p/3852424.html
Demo:
setOnRefreshListener(OnRefreshListener): 为布局添加一个Listener setRefreshing(boolean): 显示或隐藏刷新进度条 isRefreshing(): 检查是否处于刷新状态 setColorScheme(): 设置进度条的颜色主题,最多能设置四种 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); swipeLayout = (SwipeRfreshLayout) 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); } public void onRefresh() { new Handler().postDelayed(new Runnable()) { @Override public void run() { swipeLayout.setRefreshing(false); } }, 5000); }
PS:setColorScheme()已经弃用,使用setColorSchemeResources()来设置颜色。