【发布时间】:2019-09-27 15:44:56
【问题描述】:
我设置了一个可以运行的 webview。
它从名为 index.html 的 assets 文件夹的根目录加载一个页面
我希望它是 index.html 中的 html 链接,以便能够打开可以在 assets\catalyst\index.html 中找到的本地链接
我已经在根索引文件中添加了链接,但是当我点击应用程序中的链接时,它崩溃了。
我试过了
<a href="file:///android_asset/catalyst/index.html">
<a href="./catalyst/index.html">
但都不能阻止它崩溃。
我认为这是某种权限。
我在原始 webview 上设置了很多“getSettings”,希望能覆盖所有权限,但无济于事。
这是根 index.html 中的链接
<a href="file:///android_asset/catalyst/index.html"><img src="./homepage/catalystimage.jpg" alt="catalystimage"></a>
这是在允许第一个 webview 的 loadurl 的 Java 文件中。
webView=findViewById(R.id.webviewid);
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl("file:///android_asset/index.html");
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setAllowContentAccess(true);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setAllowFileAccessFromFileURLs(true);
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
WebView.setOverScrollMode(View.OVER_SCROLL_NEVER);````
i want it to load the local index.html file from the subfolder.
it crashes the app.
【问题讨论】:
-
启用 webview 的首次调试。打开您的第一个 HTML 文件。打开你的桌面浏览器 -> 开发者工具 -> 远程设备并选择你的安卓设备。现在您可以单击您的 href 链接并查看控制台选项卡以查看抛出的错误。
标签: android html hyperlink android-webview local