안드로이드 개발 질문/답변
(글 수 45,052)
웹킷을 사용한 웹 페이지 뷰어를 만들려고
우선 프로젝트 하나 만들었구요
그 상태에서 그대로 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"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<LiinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="8">
<Button
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="사이트홈"
android:layout_weight="1"
android:textSize="8pt"/>
<Button
android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="포털"
android:layout_weight="1"
android:textSize="8pt"/>
<Button
android:id="@+id/Button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="닫기"
android:layout_weight="1"
android:textSize="8pt"/>
</LiinearLayout>
</LinearLayout>
그리고 프로젝트명.java 파일은 다음과 같이 수정했구요.
package com.SeiYong.homepageviewer;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
public class SeiYongHomePageViewer extends Activity {
private static final String URL1="http://m.daum.net/";
private static final String URL2="http://m.naver.com/";
WebView webview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(URL1);
webview.setWebViewClient(new SeiYongHomePageViewerClient());
Button b1 = (Button)findViewById(R.id.Button01);
Button b2 = (Button)findViewById(R.id.Button02);
Button b3 = (Button)findViewById(R.id.Button03);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(URL1);
webview.setWebViewClient(new SeiYongHomePageViewerClient());
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(URL2);
webview.setWebViewClient(new SeiYongHomePageViewerClient());
}
});
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
finish();
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
if((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()){
webview.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
private class SeiYongHomePageViewerClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
이렇게 하고 저장했더니
이러면 컴파일 되고 apk 파일까지 정상 생성 되는데
실행해보면 어플리케이션이 실행되지 않고 에러만 뜨면서 (프로세스 ~ 에 예상치 못한 오류 발생 ~)
실행이 안 됩니다.
귀찮으시고 번거로우시겠지만 제가 중학생이고 지금 관심있어서 처음 해보는 건데
이렇게 막히니 답답해서 그러는데 답변 좀 부탁드릴게요 ㅠㅠ