Android > Webview - ÀÎÅͳÝâ ¶ç¿ì±â
µî·ÏÀÏ : 2017-07-06 17:40
Á¶È¸¼ö : 53,218
WebSite ¹× htmlÆÄÀÏÀ» º¸¿©ÁÖ´Â WebView¿¡ ´ëÇØ ¾Ë¾Æº¼ °ÍÀÌ´Ù.
1. layout/main.xml ¼Ò½ºÄÚµå
- layout Æú´õ¿¡ xmlÆÄÀÏÀ» Çϳª ¸¸µç´Ù.
- LinearLayout¾È¿¡ WebView¸¦ ±¸¼ºÇÏ°í WebView¿¡ id ¼Ó¼ºÀ» ÁØ´Ù.
¾Æ·¡´Â main.xml ¼Ò½º ÀÔ´Ï´Ù.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<WebView
android:id="@+id/webView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
2. MyWebView.java ¼Ò½ºÄÚµå
¿©±â¼ ÁÖÀÇÇÒ Á¡Àº WebViewClient¸¦ »ó¼Ó¹Þ´Â Ŭ·¡½º¸¦ ÁöÁ¤ÇÔÀ¸·Î¼, ¾Èµå·ÎÀ̵åÀÇ ÀÎÅÍ³Ý ºê¶ó¿ìÀú°¡ ¾Æ´Ñ ³»°¡¸¸µç ¾îÇà ³»¿¡ ºê¶ó¿ìÀú¸¦ ¶ç¿ï ¼ö ÀÖ´Ù.
public class MyWebView extends Activity {
final Activity activity = this;
ProgressDialog mProgress;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView infoWebView = (WebView)findViewById(R.id.webView01);
infoWebView.setWebViewClient(new InfoWebViewClient()); // ³»²¨ webview »ç¿ë ¸í½Ã
infoWebView.getSettings().setJavaScriptEnabled(true); // ÀÚ¹Ù ½ºÅ©¸³½º »ç¿ë
infoWebView.loadUrl("http://m.naver.com"); // Load URL
}
public class InfoWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
3. AndroidManifest.xml ÆÛ¹Ì¼Ç Ãß°¡
- manifest.xmlÆÄÀÏ¿¡ ÀÎÅÍ³Ý Æ۹̼ÇÀ» ÁÖ¾î¾ß ÀÎÅÍ³Ý ºê¶ó¿ì¡ÀÌ °¡´ÉÇÏ´Ù.
<uses-permission android:name="android.permission.INTERNET" />