WebView下拉刷新Demo
来源:互联网 发布:淘宝店铺年度运营计划 编辑:程序博客网 时间:2024/06/01 09:34
这里是xml布局文件
<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>
现在创建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>
最后,是我们MainActivity中的示例
package com.example.webviewrefresh;import android.os.Bundle;import android.app.Activity;import android.support.v4.widget.SwipeRefreshLayout;import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;import android.view.Menu;import android.view.View;import android.webkit.WebChromeClient;import android.webkit.WebView;import android.webkit.WebViewClient;public class MainActivity extends Activity { private SwipeRefreshLayout swipeLayout;private WebView webview;@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); webview = (WebView) findViewById(R.id.webview); swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container); swipeLayout.setOnRefreshListener(new OnRefreshListener() {@Overridepublic void onRefresh() {// TODO Auto-generated method stubwebview.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.loadUrl("https://www.baidu.com/"); webview.getSettings().setJavaScriptEnabled(true); webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webview.requestFocus(); webview.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); //设置进度条 webview.setWebChromeClient(new WebChromeClient(){ @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress == 100) { swipeLayout.setRefreshing(false); } else { if (!swipeLayout.isRefreshing()) swipeLayout.setRefreshing(true); } super.onProgressChanged(view, newProgress); } }); } }
好了,接下里你可以试一试了,希望有所帮助
0 0
- WebView下拉刷新Demo
- WebView下拉刷新Demo
- WebView下拉刷新解决办法
- Android WebView下拉刷新
- WebView 下拉刷新
- Android webview 下拉刷新
- android webview 下拉刷新
- android webview 下拉刷新
- 下拉刷新Demo
- iOS swift webview下拉刷新
- PullRefreshLayout+WebView实现下拉刷新
- Android--SwipeRefreshLayout下拉刷新Demo
- 下拉刷新demo的总结
- SwiperrefreshLayout实现下拉刷新(demo)
- tableView 下拉刷新动画demo
- webview里面的js下拉刷新
- 自定义可下拉刷新的WebView
- 【Android】Webview 如何使用SwipeRefreshLayout下拉刷新
- LeetCode 8. String to Integer (atoi)简单易懂的解法
- MTK FileManager无法分享视频到Youtube应用
- 367ValidPerfectSquare
- struts2 中文乱码问题
- asp.net spring.net+mvc 和j2ee spring mvc的思考
- WebView下拉刷新Demo
- -fpic -fPIC -fpie -fPIE
- NSEnumerator用法及找到添加到view中最上层的subview
- 使用Spring Cloud Zuul实现动态路由
- MySQL 索引介绍 属性介绍 注意事项
- java调色板的代码
- mysql主从复制配置记录
- MobileWeb 适配总结
- iOS 瀑布流基本实现