회원로그인
[Source] WebView를 이용해서, 이전 웹페이지로 이동
10년 전
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();
}
}
}
}
추천 : 488
추천
목록