package com.tbaike.HelloWebView
51Testing软件测试网:Fw+f2a"A0J!|a `
package com.tbaike.HelloWebView;
3U4x-Ro9z,dFvW0
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
51Testing软件测试网l f g|6ZYs{]-O
public class HelloWebViewActivity extends Activity {
/** Called when the activity is first created. */
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("http://www.tbaike.com");
webview.setWebViewClient(new HelloWebViewClient());
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
WebView webview = null;
if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
webview.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
51Testing软件测试网~/l1p.f1? ].J!n
class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
51Testing软件测试网&RZ0u[;\YM9|1I
}
51Testing软件测试网'@AM1L6\
main.xml
Nh4PhM-eS)?0
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:layout_marginRight="1px">
51Testing软件测试网
I.X K'GUxL%Bn
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent" android:layout_height="fill_parent"/>
51Testing软件测试网9gilU#IjR
</LinearLayout>
51Testing软件测试网yJk5w:f^0`U]
AndroidManifest.xml
51Testing软件测试网:n YtA#R$Y
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tbaike.HelloWebView"
android:versionCode="1"
android:installLocation="auto" android:versionName="1.1">
<uses-sdk android:minSdkVersion="8" />
;y
oX:FV"sE0
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloWebViewActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
;eKU@jC4s0
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>