要把項目改成android版本的,用到WebView類:
1、首先必須在AndroidManifest.xml裡配置如下:
目的是允許該控制項訪問瀏覽器資源
</activity> </application> <uses-permission android:name="android.permission.INTERNET" />
2、在你所要載入的設定檔裡面配置個WebView(layout檔案夾,main.xml):
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <WebView android:id="@+id/WebView01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/webview" />
3、邏輯代碼如下:
private WebView webview;
private String url="file:///android_asset/show.html";
//訪問本地檔案show.html,檔案須放在工程檔案的asset目錄
//url="content://com.android.htmlfileprovider/sdcard/index.html";
-----開啟本地sd卡內的index.html檔案
//url=("http://wap.baidu.com);
-----開啟指定URL的html檔案
.
.
.
webview=(WebView)findViewById(R.id.WebView01); webview.getSettings().setJavaScriptEnabled(true); webview.loadUrl(url);
4、訪問web或者資源的其他方法:
直接用Url訪問:
Uri uri = Uri.parse("http://www.example.com"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent);
2.使用TextView顯示HTML方法
TextView text1 = (TextView)findViewById(R.id.TextView02);text1.setText(Html.fromHtml(“<font size='20'>網頁內容</font>”));