首先在res==》drawable中設置樣式html
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 背景 gradient是漸變,corners定義的是圓角 --> <item android:id="@android:id/background"> <shape> <corners android:radius="1dp" /> <solid android:color="#E2E2E2" /> </shape> </item> <!-- 進度條 --> <item android:id="@android:id/progress"> <clip> <shape> <corners android:radius="1dip" /> <solid android:color="#ff3f51b5" /> </shape> </clip> </item> </layer-list>
XML中在WebView上方 標題下方設置html5
<ProgressBar android:id="@+id/html5_currency_progressbar_id" style="@android:style/Widget.ProgressBar.Horizontal" android:layout_width="fill_parent" android:layout_height="3.0dip" android:progressDrawable="@drawable/detail_progress" /> <!--android:layout_below="@+id/aaaa"//在某元素的的下方--> <!--android:layout_alignBottom="@+id/aaaa"//本元素的下邊緣和某元素的的下邊緣對齊-->
代碼中調用android
mWeb = (WebView) findViewById(R.id.web); progressBar = (ProgressBar) findViewById(R.id.html5_currency_progressbar_id); mWeb.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { Log.e("TAG", "onProgressChanged: " + progress); if (progressBar != null) { if (progress == 100) { progressBar.setVisibility(View.GONE); } else { progressBar.setProgress(progress); } } } }); mWeb.loadUrl(url);