 |
|
|  |
¾Èµå·ÎÀ̵å À¥ºä(Android WebView) ¿¹Á¦ |
|
|
 |
10³â Àü |
¾Èµå·ÎÀÌµå °³¹ß ½Ã ¸¹ÀÌ »ç¿ëÇÏ´Â À¥ºä(WebView)¿¹Á¦ ¼Ò½ºÀÔ´Ï´Ù.
¾îÇÿ¡¼ °íÁ¤µÈ ÇÁ·¹ÀÓ ¾È¿¡ À¥ÆäÀÌÁö¸¦ ¶ç¿ì´Â ±â´ÉÀÔ´Ï´Ù.
MainActivity
package com.example.h5bak_webview;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
public class MainActivity extends Activity {
WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview = (WebView)findViewById(R.id.webview);
webview.setWebViewClient(new WebClient()); // ÀÀ·æÇÁ·Î±×·¥¿¡¼ Á÷Á¢ url ó¸®
WebSettings set = webview.getSettings();
set.setJavaScriptEnabled(true);
set.setBuiltInZoomControls(true);
webview.loadUrl("http://www.google.com");
findViewById(R.id.btnStart).setOnClickListener(onclick);
}
OnClickListener onclick =new OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("Ŭ¸¯");
String url= null;
EditText add = (EditText)findViewById(R.id.add);
url = add.getText().toString();
webview.loadUrl(url);
}
};
class WebClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
activity_main.xml
<!--?xml version="1.0" encoding="utf-8"?-->
<linearlayout android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<edittext android:id="@+id/add" android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="http://www.google.com">
<linearlayout android:layout_height="wrap_content" android:layout_width="fill_parent">
<button android:id="@+id/btnStart" android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="À̵¿">
<webview android:id="@+id/webview" android:layout_height="fill_parent" android:layout_width="fill_parent" android:focusableintouchmode="true" android:focusable="true">
</webview></button></linearlayout></edittext></linearlayout>
½ÇÇà°á°ú
|
|
̵̧ : 1135 |
̵̧
¸ñ·Ï
|
|
|  |
|