SwipeRefreshLayout 是谷歌官方下拉刷新控件,4.0以下的版本需要用到 android-support-v4.jar包才能用到

android-support-v4.jar 包下载地址:http://download.csdn.net/detail/h7870181/7784247

官网API地址:https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html

GitHub Demo下载地址: https://github.com/stormzhang/SwipeRefreshLayoutDemo



SwipeRefreshLayout 使用起来是非常简单的,只需要在可以滑动的控件外层添加即可,如:WebView、ListView和ScroolView.

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


常用方法:

void setOnRefreshListener(SwipeRefreshLayout.OnRefreshListener listener) 设置刷新监听器

void setColorSchemeColors(int color1, int color2, int color3, int color4) 设置四种颜色进度条样式

void setRefreshing(boolean refreshing) 隐藏或显示进度条

boolean isRefreshing() 判断进度条是否显示


结合WebView使用也挺简单的,可以实现一些功能,下拉刷新当前网页、点击网页在当前页面中浏览并显示SwipeRefreshLayout进度条,整体来说还是不错的

public class Fragment5 extends Fragment {private View view;public WebView webview;private SwipeRefreshLayout swipeLayout;@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {view = inflater.inflate(R.layout.activity_fragment5, null);swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container);swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {@Overridepublic void onRefresh() {//重新刷新页面webview.loadUrl(webview.getUrl());}});swipeLayout.setColorScheme(R.color.holo_blue_bright,R.color.holo_green_light, R.color.holo_orange_light,R.color.holo_red_light);webview = (WebView)view.findViewById(R.id.webview);webview.loadUrl("http://blog.csdn.net/h7870181");//添加javaScript支持webview.getSettings().setJavaScriptEnabled(true); //取消滚动条webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);//触摸焦点起作用webview.requestFocus();//点击链接继续在当前browser中响应 webview.setWebViewClient(new WebViewClient(){@Overridepublic boolean shouldOverrideUrlLoading(WebView view, String url) {view.loadUrl(url);                       return true;       }});//设置进度条webview.setWebChromeClient(new WebChromeClient(){@Overridepublic void onProgressChanged(WebView view, int newProgress) {if (newProgress == 100) {//隐藏进度条swipeLayout.setRefreshing(false);            } else {                if (!swipeLayout.isRefreshing())                swipeLayout.setRefreshing(true);            }super.onProgressChanged(view, newProgress);}});return view;}}

差点忘了贴出color.xml资源文件了,我呵了个呵!

<?xml version="1.0" encoding="utf-8"?><resources>    <!-- A light Holo shade of blue -->    <color name="holo_blue_light">#ff33b5e5</color>    <!-- A light Holo shade of green -->    <color name="holo_green_light">#ff99cc00</color>    <!-- A light Holo shade of red -->    <color name="holo_red_light">#ffff4444</color>    <!-- A dark Holo shade of blue -->    <color name="holo_blue_dark">#ff0099cc</color>    <!-- A dark Holo shade of green -->    <color name="holo_green_dark">#ff669900</color>    <!-- A dark Holo shade of red -->    <color name="holo_red_dark">#ffcc0000</color>    <!-- A Holo shade of purple -->    <color name="holo_purple">#ffaa66cc</color>    <!-- A light Holo shade of orange -->    <color name="holo_orange_light">#ffffbb33</color>    <!-- A dark Holo shade of orange -->    <color name="holo_orange_dark">#ffff8800</color>    <!-- A really bright Holo shade of blue -->    <color name="holo_blue_bright">#ff00ddff</color></resources>


没多大技术含量,纯属积累学习,还望大家见谅!


成功源于不断的学习和积累 !




更多相关文章

  1. 安全新手入坑——HTML标签
  2. Nginx系列教程(四)| 一文带你读懂Nginx的动静分离
  3. Android(安卓)在代码中书写布局(xml)配置
  4. android.view.ViewRootImpl$CalledFromWrongThreadException: On
  5. Android(安卓)使用WebView点击左上角返回键和物理返回键回到上一
  6. android 设置状态栏颜色
  7. android直播app礼物连击动画效果
  8. Android第二周(第二部分)-listview
  9. Android(安卓)Studio 改变app启动页面

随机推荐

  1. Android:开发环境搭建
  2. Android(安卓)根据城市名称获取经纬度
  3. 在it混了四年了,android开始半个多年头,发
  4. Android中如何修改CheckBox的颜色
  5. Android写文件到SDCard的一般过程和代码
  6. Android(安卓)Studio:正确引入so文件的方
  7. Android进程保活
  8. ntfs在android平台上的移植
  9. Android回调——Android模块化编程
  10. Android之SurfaceView学习