*********************布局文件**********************************
<?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.webkit.WebView
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
</android.webkit.WebView>
</LinearLayout>
***********************代码***************************************
package com.movexy.newstudent;
import com.movexy.login.R;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class xsbd extends Activity {
private WebView webview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newstudent);
webview = (WebView)findViewById(R.id.webView1);
WebSettings webSettings = webview.getSettings();
webSettings.setSavePassword(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(false);
webview.loadUrl("file:///android_asset/xsbd.html");//本地
//webview.loadUrl("http://www.baidu.com");//远程
//=================================================
// String htmldata="";//网页代码
// String targeturl="";//目标网址(具体)
// String baseurl="";//连接目标网址失败进入的默认网址
// webview.getSettings().setDefaultTextEncodingName("GB2312");
// webview.loadData(htmldata, "xsbd/html", "utf-8");
// webview.loadDataWithBaseURL(targeturl, htmldata, "xsbd/html", "utf-8", baseurl);
}
}
注:横线上线为2种方法
/android_asset中的asset不要写成assets