RemseActivity.java
package com.dku.RemseHompy;
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 RemseActivity extends Activity {
private static final String URL1="http://m.daum.net/mini";
private static final String URL2="http://m.blog.naver.com/remse";
WebView webview;
/* Called when the activity is first created. */
@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 RemseActivityClient());
Button b1 = (Button)findViewById(R.id.Button02);
Button b2 = (Button)findViewById(R.id.Button03);
Button b3 = (Button)findViewById(R.id.Button04);
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 RemseActivityClient());
}
});
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 RemseActivityClient());
}
});
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 RemseActivityClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
//HelloWebViewClient 클래스는 WebViewClient 클래스를 상속받아서 만들었는데,
//WebViewClient 는 WebView 에서 로딩한 웹페이지의 링크를 클릭했을 때,
//해당 URL을 로딩하는 데 필요합니다.
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/back" android:scrollbars="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical">
<TextView android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello" android:layout_gravity="center" android:textColor="@color/brightGreen" android:textColorHint="@color/brightGreen2"></TextView><TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/introduce" android:textColor="@color/black" android:layout_gravity="center_vertical"></TextView>
<TextView android:id="@+id/TextView03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/introduce1" android:textColor="@color/black"></TextView>
<Gallery android:id="@+id/Gallery01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/myimage" android:layout_gravity="center"></Gallery>
<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:autoLink="web" android:text="@string/comeon"></Button>
<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>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="8">
<Button
android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Home"
android:layout_weight="1"
android:textSize="8pt"/>
<Button
android:id="@+id/Button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Portal"
android:layout_weight="1"
android:textSize="8pt"/>
<Button
android:id="@+id/Button04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Close"
android:layout_weight="1"
android:textSize="8pt"/>
</LinearLayout>
</LinearLayout>
Manifest
<uses-permission android:name="android.permission.INTERNET" /> //추가완료.
첨부된 그림파일은 에러화면이예요 ㅠㅠ
계속 문제점 찾아봤는데.. 도저히 알길이 없어 막막합니다..ㅠㅠ
문제를 해결할 수 있게 도와주세요 ㅠㅠ