最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Android编程实现WebView添加进度条的方法
时间:2017-03-16 编辑:简简单单 来源:一聚教程网
标准的XML界面
代码如下 | 复制代码 |
android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> android:id="@+id/pb" style="?android:attr/progressBarStyleHorizontal" android:layout_width="fill_parent" android:layout_height="8dip" android:indeterminateOnly="false" android:max="100" android:progressDrawable="@drawable/progress_bar_states"> android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent"/> |
上面声明了两个控件,一个是progressBar 一个是 webview,progressbar用来显示webview控件的加载进度的
值得注意的是我们重写的progressdrawable这个属性,把原来难看的加载条,稍稍美化了一些,下面就是xml代码:
代码如下 | 复制代码 |
android:startColor="#ff0000" android:centerColor="#ffa600" android:endColor="#ff5500" /> android:startColor="#234" android:centerColor="#234" android:endColor="#a24" /> android:startColor="#33000001" android:centerColor="#40000000" android:endColor="#44000000" /> |
下面是Activity的java代码:
代码如下 | 复制代码 |
ProgressBar pb; @Override protectedvoidonCreate(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(newWebViewClient() ); webView.loadUrl("http://www.x.com"); } privateclassWebViewClientextendsWebChromeClient { @Override publicvoidonProgressChanged(WebView view,intnewProgress) { pb.setProgress(newProgress); if(newProgress==100){ pb.setVisibility(View.GONE); } super.onProgressChanged(view, newProgress); } } |
相关文章
- Android的进度条控件描述 03-07
- Android实现环形进度条代码 01-18
- sora软件价格介绍 02-22
- sora官网入口地址一览 02-22
- Sora生成的视频使用教程 02-22
- 《梦幻西游》元宵灯谜线索答案大全2024 02-22