웹 뷰 (Web View)

웹 & 안드로이드/Android|2013. 10. 18. 09:15

웹 뷰 : 안드로이드 앱 상에서 웹 페이지를 볼 수 있도록 하는 뷰.


웹 클라이언트 : 웹 뷰에게 웹 페이지를 공급해주는 것. 웹 뷰는 웹 클라이언트로부터 페이지를 공급받아 뷰 화면에 보여준다.


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
 
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
 
public class MainActivity extends Activity {
    EditText et;
    Button b;
    WebView wv;
    InputMethodManager imm;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b = (Button) findViewById(R.id.button1);
        et = (EditText) findViewById(R.id.editText1);
        wv = (WebView) findViewById(R.id.webView1);
        
        imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
        
        wv.setWebViewClient(new MyWebViewclient());
        WebSettings ws = wv.getSettings();
        ws.setJavaScriptEnabled(true);
        ws.setBuiltInZoomControls(true);
        
        wv.loadUrl("http://www.naver.com/");
        
        b.setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View v) {
                wv.loadUrl(et.getText().toString());
                imm.hideSoftInputFromWindow(
                        getCurrentFocus().getWindowToken(),     
                        InputMethodManager.HIDE_NOT_ALWAYS);
                
            }
        });
        
    }
        
    class MyWebViewclient extends WebViewClient{
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return super.shouldOverrideUrlLoading(view, url);
        }
    }
}
 


댓글()