Nim*_*van 11
Android HTML资源中描述了一种更简单的方法,并引用了其他资源.它对我来说很好.
将HTML文件放在root中的"assets"文件夹中,使用以下命令加载:
webView.loadUrl("file:///android_asset/filename.html");
Run Code Online (Sandbox Code Playgroud)
我假设你想在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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这将从项目资产/文件夹中读取文件'index.html'.
| 归档时间: |
|
| 查看次数: |
12466 次 |
| 最近记录: |