[Source] WebView¸¦ ÀÌ¿ëÇؼ, ÀÌÀü À¥ÆäÀÌÁö·Î À̵¿ |
|
|
 |
8³â Àü |
WebView¸¦ »ç¿ë½Ã, ¹æ¹®ÇÑ ÀÌÀü ÆäÀÌÁö¹× (ÀÌÀüÆäÀÌÁö¿¡¼) ´ÙÀ½ÆäÀÌÁö À̵¿½ÃÅ°´Â ¸Þ¼Òµå »ç¿ë¿¹Á¦ ÀÔ´Ï´Ù.
package co.kr.codein;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.Button;
import android.view.View.OnClickListener;
public class WebViewExam extends Activity implements OnClickListener{
private final int FP = ViewGroup.LayoutParams.FILL_PARENT;
private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
private Button buttonBack;
private Button buttonForward;
private WebView webview;
@Override protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
setContentView(linearLayout);
LinearLayout btnLinearLayout = new LinearLayout(this);
btnLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
buttonBack = new Button(this);
buttonBack.setText("Back");
buttonBack.setOnClickListener(this);
buttonForward = new Button(this);
buttonForward.setText("Forward");
buttonForward.setOnClickListener(this);
btnLinearLayout.addView(buttonBack, createParam(WC, WC));
btnLinearLayout.addView(buttonForward, createParam(WC, WC));
webview = new WebView(this);
webview.loadUrl("http://cafe.naver.com/aphone.cafe");
linearLayout.addView(btnLinearLayout, createParam(FP, WC));
linearLayout.addView(webview, createParam(WC, WC));
}
private LinearLayout.LayoutParams createParam(int w, int h){
return new LinearLayout.LayoutParams(w, h);
}
public void onClick(View v) {
//Back ¹öÆ° Ŭ¸¯½Ã, ÀÌÀüÆäÀÌÁö·Î À̵¿
if (v == buttonBack){
if (webview.canGoBack()){
webview.goBack();
}
}
//Forward ¹öÆ° Ŭ¸¯½Ã, ´ÙÀ½ÆäÀÌÁö·Î À̵¿
else if (v == buttonForward){
if (webview.canGoForward()){
webview.goForward();
}
}
}
}
|
|
̵̧ : 337 |
̵̧
¸ñ·Ï
|
|