webview 사용하기 (ProgressBar 로딩바 포함)
	
프로그래밍/Android (Java)2015. 11. 17. 12:40
		
  
반응형
    
    
    
  설명이 없어도 코드를 보면 바로 사용하실 수 있습니다.
여러가지 기능 중 가장 기본적인 코드이고, 자세한 내용은 Developer Android Reference 에서 보실 수 있습니다. 
| Activity Code & Layout XML Code | 
Activity
| 
 1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62  | 
package me.croute.webview;import me.croute.R;import android.app.Activity;import android.os.Bundle;import android.webkit.WebChromeClient;import android.webkit.WebView;import android.webkit.WebViewClient;import android.widget.ProgressBar;/** * 웹뷰 사용 기본 예제 *  * @author croute * @since 2011.07.27 * @url http://croute.me/458 */public class WebViewExampleActivity extends Activity{         private ProgressBar mPbProgress;    private WebView mWvBrowser;                  /* (non-Javadoc)     * @see android.app.Activity#onCreate(android.os.Bundle)     */    @Override    public void onCreate(Bundle savedInstanceState)    {        super.onCreate(savedInstanceState);        setContentView(R.layout.web_view_example_activity);                 mPbProgress = (ProgressBar)findViewById(R.id.web_view_example_activity_pb_progress);        mWvBrowser = (WebView)findViewById(R.id.web_view_example_activity_wv_browser);                 mWvBrowser.getSettings().setJavaScriptEnabled(true);        mWvBrowser.setWebViewClient(new WebViewClient());               mWvBrowser.loadUrl(DEFAULT_URL);                         // 웹뷰의 진행 상태를 표시하기 위한 프로그레스바        mWvBrowser.setWebChromeClient(new WebChromeClient()         {                 public void onProgressChanged(WebView view, int progress)                {                     if (progress<100)                   {                       mPbProgress.setVisibility(ProgressBar.VISIBLE);                   }                   else if (progress==100)                   {                       mPbProgress.setVisibility(ProgressBar.GONE);                   }                   mPbProgress.setProgress(progress);                 }           });             }} | 
Layout XML
| 
 1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16  | 
<?xml version="1.0" encoding="utf-8"?>              android:layout_width="fill_parent"              android:layout_height="fill_parent"              android:orientation="vertical"              android:background="#FFFFFF" >    <ProgressBar        android:id="@+id/web_view_example_activity_pb_progress"        android:layout_width="fill_parent"        android:layout_height="5dp"        style="?android:attr/progressBarStyleHorizontal" />    <WebView        android:id="@+id/web_view_example_activity_wv_browser"        android:layout_width="fill_parent"        android:layout_height="fill_parent" /></LinearLayout> | 
 
| ScreenShot & Project files | 
[출처] http://croute.me/458
반응형
    
    
    
  '프로그래밍 > Android (Java)' 카테고리의 다른 글
| 웹에서 액티비티 호출하기 (0) | 2015.11.19 | 
|---|---|
| HTML을 안드로이드 웹뷰에 모두 보이게 하기 (0) | 2015.11.19 | 
| TextView 상, 하 여백 줄이기 (0) | 2015.11.13 | 
| layout 에서 공백 채우기 (0) | 2015.11.13 | 
| Simple JSON Parsing Example in Android (리스트뷰, 그리드뷰 아님) (0) | 2015.11.11 | 
댓글()
								







