개발도구/aOS - 안드로이드 개발
[안드로이드] webview
Hay's App
2012. 2. 20. 17:22
웹뷰 활용 : http://croute.me/405
Activity
Layout XML
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 > |