我想在我的Android模拟器显示一个静态的HTML页面。一世 不知道如何做到这一点。请人帮助我。
I want to display one static HTML page in my android emulator. I don't know how to do this. Please anybody help me.
我假设你想在web视图显示自己的网页?
I'm assuming you want to display your own page in a webview?
创建此为您的活动:
public class Test extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webview = new WebView(this);
setContentView(webview);
try {
InputStream fin = getAssets().open("index.html");
byte[] buffer = new byte[fin.available()];
fin.read(buffer);
fin.close();
webview.loadData(new String(buffer), "text/html", "UTF-8");
} catch (IOException e) {
e.printStackTrace();
}
}
}
这将从您的项目资产/文件夹中读取文件'的index.html'。
This will read the file 'index.html' from your project assets/ folder.