十五年测试老手,长期负责WEB\APP 项目测试,目前主要负责团队管理工作。

Android开发练习之Hello, WebView

上一篇 / 下一篇  2011-09-04 13:10:15 / 个人分类:Android

文章来源
  • 文章来源:【原创】
package com.tbaike.HelloWebView
51Testing软件测试网%I\ u@&q(_?#L
package com.tbaike.HelloWebView;

@o"BQ9ssM0
import android.app.Activity;
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软件测试网\!S xSg&XdR~
}
51Testing软件测试网;a4q v M ~M Yn
main.xml

#HbfC.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>

TAG: Android android

 

评分:0

我来说两句

Open Toolbar