【发布时间】:2017-01-02 11:13:11
【问题描述】:
我在 Android 7.0 (moto g4) 中面临一个问题,我试图在 webview 中加载一个 url,但它显示一个空白屏幕。它适用于 Android M 及以下版本。
public class MainActivity extends Activity {
private String webviewURL="http://henmilholidayhomesgoa.com/player2/documentation/EULA.html";
private WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv= (WebView) findViewById(R.id.webview);
wv.getSettings().setTextZoom(60);
wv.getSettings().setBuiltInZoomControls(true);
wv.getSettings().setJavaScriptEnabled(true);
wv.loadUrl(webviewURL);
}
}
注意:- 代码中提到的 url 不是实际的 url,很遗憾我不能分享 :(。它是一个带有 https 的 url。但是帖子中给定的 url 确实有效,如果有,请告诉我需要其他输入。在此先感谢
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
</RelativeLayout>
【问题讨论】:
-
您打开的是什么类型的 url,我的意思是说任何文档或网站或 pdf 或任何其他媒体类型?
-
如果上面的网址可以正常工作,那么您想要的网址也应该如此。您帖子中的网址有 http 尝试使用 https 输入其他网址说:“google.com”
-
您需要找到一些可以重现您可以在您的问题中提出的问题的 URL。
-
当我找到@CommonsWare 时我会更新它
-
我将 html 页面保存到我的资产文件夹并尝试它可以正常工作(在 android 7.0 中),但其中显示了一些 ASCII 字符。所以我尝试以编程方式检索 url 内容并使用 webview.loadData(response, "text/html; charset=utf-8",null);这也有效(在android 7.0中)。有没有这方面的cmets?
标签: android webview android-7.0-nougat