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

Android开发练习之Hello, WebView

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

文章来源
  • 文章来源:【原创】
package com.tbaike.HelloWebView
51Testing软件测试网:Fw+f2a"A0J!|a `
package com.tbaike.HelloWebView;

3U4x-Ro9z,d FvW0
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
51Testing软件测试网lf 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.XK'GUxL%Bn
    <WebView 
        android:id="@+id/webview"
        android:layout_width="fill_parent" android:layout_height="fill_parent"/>
51Testing软件测试网9gil U#IjR
</LinearLayout>
51Testing软件测试网y Jk5w:f^0`U]
AndroidManifest.xml
51Testing软件测试网:nYtA#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>

TAG: Android android

 

评分:0

我来说两句

Open Toolbar