package com.tbaike.HelloWebView
51Testing软件测试网%I\ u@&q(_?#L
package com.tbaike.HelloWebView;
@o"BQ9ssM0
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
`P)^*j.X0
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);
}
}
G#O'x.We;{0
class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
51Testing软件测试网\!SxSg&XdR~
}
51Testing软件测试网;a4q
vM~M Yn
main.xml
#Hb fC.Z0`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">
GBj6v9gv0
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent" android:layout_height="fill_parent"/>
51Testing软件测试网k'C!ee6f#I&P I
</LinearLayout>
yc8Ms3Z{0
AndroidManifest.xml
KU&Q
Ch#J2Zv0
<?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" />
+F+y2dFg
Rt2N
Z0
<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>
.]a)Tri0
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>