2번 빼고 permission 권한 INTERNET을 주어야 한다 이전 게시물 참고

간단히 말하면 manifest.xml 접근 -> permission 탭 -> add -> uses -> INTERNET -> 저장

(밑으로 내려갈수록 발전되는 기능을 볼수 있음 )
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <WebView
        android:id="@+id/webkit"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    
</LinearLayout>


package com.commonsware.android.browser1;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class BrowserDemo1 extends Activity {
    WebView browser;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        browser = (WebView)findViewById(R.id.webkit);
        
        browser.loadUrl("http://m.naver.com");
        
    }
}





<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <WebView
        android:id="@+id/webkit"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>


package com.commonsware.android.browser2;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class BrowserDemo2 extends Activity {
	WebView browser;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        browser = (WebView)findViewById(R.id.webkit);
        
        
        String msg = "<meta http-equiv="\"Content-Type\"" content="\"text/html;" 
        		charset="UTF-8\"">Hello, world! 안녕하세요!";        
        
        browser.loadData(msg,"text/html","UTF-8");
    }
}





<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <WebView
        android:id="@+id/web"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>


package com.commonsware.android.browser3;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class BrowserDemo3 extends Activity {
	WebView mWeb;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        mWeb = (WebView)findViewById(R.id.web);
        
        mWeb.setWebViewClient(new MyWebClient());
        WebSettings set = mWeb.getSettings();
        set.setJavaScriptEnabled(true);
        set.setBuiltInZoomControls(true);
        mWeb.loadUrl("http://m.nate.com");
    }
    
    //HTML페이지에서 링크를 클릭할 때 발생하는 이벤트를 처리하는 클래스
    class MyWebClient extends WebViewClient{
    	//전달되는 인자
    	//WebView view : 실행중인 WebView 객체
    	//String url : 클릭한 링크(링크를 다시 받아 내부에서 처리)
    	
    	public boolean shouldOverrideUIrlLoading(WebView view, String url){
    		view.loadUrl(url);
    		return true;
    	}
    }
}




'Android > 기본' 카테고리의 다른 글

Access Web  (0) 2012.04.28
NetWork Wifi , 3G  (0) 2012.04.28
Handler 사용하기 (로딩 표시?)  (0) 2012.04.28
Activity 생명주기  (0) 2012.04.28
Message 팝업창 띄우기 경고창,토스트 표시,Progress Dialog  (0) 2012.04.28

+ Recent posts