您可以使用以下命令从“资产”文件夹中打开一个 html 页面
//help_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/helpwebview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
在资源文件中,例如在strings.xml 中。“file:///android_asset”对应Android项目中的“Assets”文件夹。
<string name="help_url">file:///android_asset/help/index_de.html</string>
//HelpActivity的代码
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class HelpActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.help_activity);
WebView browser = (WebView)findViewById(R.id.helpwebview);
WebSettings settings = browser.getSettings();
settings.setJavaScriptEnabled(true);
settings.setBuiltInZoomControls(true);
browser.loadUrl(getString(R.string.help_url));
}
}