Jac*_*lva 2 android android-webview progress-bar
我正在将一个WebView加载到LinearLayout,并希望在此布局中显示ProgressBar,直到WebView完全加载.我通过以下链接,它们看起来真的很棒,但我不想使用ProgressDialog,而是我想要在布局中使用进度条.
http://xjaphx.wordpress.com/2011/07/31/load-webview-with-progressdialog/
我该怎么办?
比如说,
if(pos==0)
{
mLayout.setVisibility(View.VISIBLE);
mWeb.loadUrl("http://android.stackexchange.com/");
}
Run Code Online (Sandbox Code Playgroud)
在里面mLayout
我想显示一个进度条,直到页面显示出来.
要在webview中定义进度条:
1.在布局中定义ProgressBar
和Webview
内部,如下所示:
<ProgressBar android:id="@+id/progressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="8px"
android:max="100"
android:visibility="gone" />
<ScrollView
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fadingEdge="none" >
<WebView
android:id="@+id/webkit"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
2.在您的活动中:
progressBar = (ProgressBar)findViewById(R.id.progressbar);
progressBar.setProgress(0);
progressBar.setVisibility(View.VISIBLE);
WebView mWebView = (WebView)findViewById(R.id.webkit);
mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged(WebView view, int progress) {
progressBar.setProgress(progress);
if(progress == 100) {
progressBar.setVisibility(View.GONE);
}
}
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4425 次 |
最近记录: |