Android 5.0特性(SwipeRefreshLayout)

1,实现效果

  • 实现下来刷新

Android 5.0特性(SwipeRefreshLayout)_第1张图片

 

2,实现效果

【1】添加依赖,导入V7包SwipeRefreshLayout是V4包下的,V7保护我

compile 'com.android.support:appcompat-v7:23.4.0'

添加网络权限

 

【2】把需要展示的内容用SwipeRefreshLayout包裹





  

   

   



 

【3】代码调用

  • 获取控件

  • 设置外观颜色(可以设置多种颜色的转变)

        // refreshlayout.setColorSchemeColors(Color.RED);

        refreshlayout.setColorSchemeColors(Color.RED,Color.GREEN,Color.YELLOW);

  • 设置监听,当松开的时候进行业务逻辑处理

   SwipeRefreshLayout.OnRefreshListener listener=new SwipeRefreshLayout.OnRefreshListener() {

            //松开布局

            @Override

            public void onRefresh() {

                webView.loadUrl("http://www.itheima.com");

            }

        };

        refreshlayout.setOnRefreshListener(listener);
  • 实现代码

public class MainActivity extends AppCompatActivity {





    private WebView webView;

    private SwipeRefreshLayout refreshlayout;





    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        refreshlayout = (SwipeRefreshLayout) findViewById(R.id.refreshlayout);

        //设置外观

        // refreshlayout.setColorSchemeColors(Color.RED);

        refreshlayout.setColorSchemeColors(Color.RED,Color.GREEN,Color.YELLOW);

        SwipeRefreshLayout.OnRefreshListener listener=new SwipeRefreshLayout.OnRefreshListener() {

            //松开布局

            @Override

            public void onRefresh() {

                webView.loadUrl("http://www.itheima.com");

            }

        };

        refreshlayout.setOnRefreshListener(listener);

        webView = (WebView) findViewById(R.id.webview);

        String url="http://www.baidu.com";

        ///设置一个禁止调用系统浏览器的对象

        webView.setWebViewClient(new WebViewClient());

        //WebChromeClient设置 处理页面加载进度

        webView.setWebChromeClient(new WebChromeClient(){

            @Override

            public void onProgressChanged(WebView view, int newProgress) {

                super.onProgressChanged(view, newProgress);

                if (newProgress == 100) {

                    refreshlayout.setRefreshing(false);//关闭刷新

                }

            }

        });

        webView.loadUrl(url);





    }

}

 

你可能感兴趣的:(Android,Android,新特性)