本文へスキップ

WebView 로딩중 에만 ProgressBar 진행상태 표시

MintState 2011年5月16日 10:58 閲覧 16305

WebView 로딩중 에만 ProgressBar 진행상태 표시

웹페이지 로딩시 프로그레스바를 보이고 로딩이 끝나면 사라지게하는 방법

[ATTACH]691[/ATTACH]

Layout

<FrameLayout
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:layout_weight="1">
	<WebView android:id="@+id/webView"
		android:layout_width="fill_parent"
		android:layout_height="fill_parent" />
	<ProgressBar android:id="@+id/progress_horizontal"
		style="?android:attr/progressBarStyleHorizontal"
		android:layout_width="fill_parent"
		android:layout_height="5dp"
		android:max="100"
		android:visibility="gone" />
</FrameLayout>

Class

ProgressBar mProgressHorizontal = (ProgressBar) findViewById(R.id.progress_horizontal);
WebView mWebView = (WebView)this.findViewById(R.id.webView);
mWebView.getSettings().setJavaScriptEnabled(true);

mWebView.setWebViewClient(new MyWebViewClient(){
	@Override
	public boolean shouldOverrideUrlLoading(WebView view, String url) {
		view.loadUrl(url);
		return true;
	}

	@Override
	public void onPageStarted(WebView view, String url, Bitmap favicon) {
		super.onPageStarted(view, url, favicon);
		mProgressHorizontal.setVisibility(View.VISIBLE);
	}

	@Override
	public void onPageFinished(WebView view, String url) {
		super.onPageFinished(view, url);
		mProgressHorizontal.setVisibility(View.INVISIBLE );
	}

	@Override
	public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
		super.onReceivedError(view, errorCode, description, failingUrl);
		Toast.makeText(Flipper_Activity.this, "로딩오류" + description, Toast.LENGTH_SHORT );
	}
});


mWebView.setWebChromeClient(new WebChromeClient(){
	@Override
	public void onProgressChanged(WebView view, int newProgress) {
		mProgressHorizontal.setProgress(newProgress);
	}
}); 

참고
http://blog.outsider.ne.kr/464
http://developer.android.com/reference/android/webkit/WebView.html

출처 : http://blog.naver.com/free2824/60123140115

共有 X Facebook LINE QR コード

コメント 0 件

最初のコメントを書いてみましょう。