티스토리 뷰










Activity 제목부분에서 WebView 의 페이지 로딩 진행상황을 progress meter 로 표시해준다.

페이지 로드가 100% 완료되면 progress meter 는 사라진다.

소스구현

  1. getWindow().requestFeature(Window.FEATURE_PROGRESS) 선언
  2. public void onProgressChanged(WebView view, int progress) 구현
 
 public class TestActivity extends Activity {
	WebView  webview ;
	final Activity activity = this;
	@Override
    public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		 getWindow().requestFeature(Window.FEATURE_PROGRESS);
		 setContentView(com.misun.samples.R.layout.sample06_a);
		 
		 webview = (WebView)findViewById(com.misun.samples.R.id.s06_webview);
		 webview.setWebChromeClient(new WebChromeClient() {
		   public void onProgressChanged(WebView view, int progress) {
		     // Activities and WebViews measure progress with different scales.
		     // The progress meter will automatically disappear when we reach 100%
		     activity.setProgress(progress * 100);
		     Log.i("TEST", "progress="+progress);
		   }
		 });
		 webview.setWebViewClient(new WebViewClient() {
		   public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
		     Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
		   }
		 });

		 webview.loadUrl("http://angmang.tistory.com");		
	}
}

progress bar가 나타나도록 setContentView 전에 설정한다.

		 getWindow().requestFeature(Window.FEATURE_PROGRESS);
		 setContentView(com.misun.samples.R.layout.sample06_a);

progress bar 진행에 따라 onProgressChanged()가 호출된다.

		 webview.setWebChromeClient(new WebChromeClient() {
		   public void onProgressChanged(WebView view, int progress) {
		     // Activities and WebViews measure progress with different scales.
		     // The progress meter will automatically disappear when we reach 100%
		     activity.setProgress(progress * 100);
		     Log.i("TEST", "progress="+progress);
		   }
		 });

에러핸들링

 

		 webview.setWebViewClient(new WebViewClient() {
		   public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
		     Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
		   }
		 });

void android.app.Activity.setProgress(int progress)

타이틀 안에서 progress bars 의 진행상황을 설정한다. requestWindowFeature(int) 설정으로 progress bars 가 보여지게 된다.

Parameters

  • progress

    The progress for the progress bar.

    Valid ranges are from 0 to 10000 (both inclusive). If 10000 is given, the progress bar will be completely filled and will fade out.

댓글