给WebView添加漂亮的加载进度条
2015-01-02 23:35
281 查看
为了增强用户体验,所有在WebView头部给加了个进度条,看起来不错哦。
布局XMl:activity_main.xml
自定义进度条:
然后就是Activity的主要代码啦:
不多说,知道大家最关心效果如何咯:
转载请注明:破晓博客 » [原创]给WebView添加漂亮的加载进度条
布局XMl:activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <WebView android:id="@+id/webView" android:layout_width="fill_parent" android:layout_height="fill_parent"/> <ProgressBar android:id="@+id/pb" style="?android:attr/progressBarStyleHorizontal" android:layout_width="fill_parent" android:layout_height="3dip" android:indeterminateOnly="false" android:max="100" android:progressDrawable="@drawable/progress_bar_states" > </ProgressBar> </RelativeLayout>
自定义进度条:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@android:id/background"> <shape> <corners android:radius="2dp" /> <gradient android:angle="270" android:centerColor="#E3E3E3" android:endColor="#E6E6E6" android:startColor="#C8C8C8" /> </shape> </item> <item android:id="@android:id/progress"> <clip> <shape> <corners android:radius="2dp" /> <gradient android:centerColor="#4AEA2F" android:endColor="#31CE15" android:startColor="#5FEC46" /> </shape> </clip> </item> </layer-list>
然后就是Activity的主要代码啦:
ProgressBar pb; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.xxx); pb = (ProgressBar) findViewById(R.id.pb); pb.setMax(100); WebView webView = (WebView) findViewById(R.id.webview); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setSupportZoom(true); webView.getSettings().setBuiltInZoomControls(true); webView.setWebChromeClient(new WebViewClient() ); webView.loadUrl("http://www.x.com"); } private class WebViewClient extends WebChromeClient { @Override public void onProgressChanged(WebView view, int newProgress) { pb.setProgress(newProgress); if(newProgress==100){ pb.setVisibility(View.GONE); } super.onProgressChanged(view, newProgress); } }
不多说,知道大家最关心效果如何咯:
转载请注明:破晓博客 » [原创]给WebView添加漂亮的加载进度条
相关文章推荐
- 给WebView添加漂亮的加载进度条
- 安卓学习笔记--- 给WebView添加漂亮的加载进度条
- webview添加网页加载进度条
- iOS WKWebView添加网页加载进度条(转)
- Android Webview添加网页加载进度条实例详解
- iOS WKWebView添加网页加载进度条
- Android WebView 加载网页添加进度条
- Android--当webview加载网页的时候在标题栏上显示加载进度
- Android--当webview加载网页的时候在标题栏上显示加载进度
- WebView内使用post加载url并添加header
- Android构建一个通用的WebView(一):标题、加载进度、JavaScript交互、用浏览器打开等
- Android开发模板------WebView加载时显示ProgressBar进度条
- ios-webview加载进度中执行多次的问题
- WebView 自定义错误界面,WebView 加载进度条,和Logding 效果
- webview中图片加载,添加放大缩小功能
- Android加载webView加载进度实现
- 在WebView中加载HTML页面时显示进度对话框的方法
- WebView 加载进度条
- WebView学习笔记(一)——网页未完成加载的等待进度条
- 为android的webview添加进度条