不多说什么了!上代码吧!很简单的东西
首先在定义一个进度条的加载时的两种颜色一个xml文件
<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>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/comm_tit"></include>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="3dip"
android:progressDrawable="@drawable/pg"
android:visibility="gone"
/>
<View
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:background="@color/line"></View>
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"></WebView>
</LinearLayout>
监听方法及实现过程
webView.setWebChromeClient(new WebChromeClient(){
@Override
public void onProgressChanged(WebView view, int newProgress) {
// TODO 自动生成的方法存根
if(newProgress==100){
//执行加载任务完成,隐藏该控件
pg1.setVisibility(View.GONE);
}
else{
pg1.setVisibility(View.VISIBLE); pg1.setProgress(newProgress); } } });//开始加载网页时显示进度条以及设置进度值
//这个问题也是今天有个朋友忽然问我,然后翻了翻之前的项目,不太懂得朋友可以直接留言咨询