进出口面临的一个问题的Android 7.0(MOTO G4),其中我尝试在web视图加载一个URL,但它显示了一个空白screen.It正在与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实际工作,请让我知道如果任何其他输入是needed.Thanks。提前
<?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>
试试这个示例代码:
在此有一个网页视图和bar.In这个代码URL进度会进度条消失尽快加载,如果在URL中的任何链接将在网页视图中打开它。
下面是Java代码:
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class ShowWebView extends Activity {
//private Button button;
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_web_view);
//Get webview
webView = (WebView) findViewById(R.id.webView1);
startWebView("http://www.androidexample.com/media/webview/login.html");
}
private void startWebView(String url) {
//Create new webview Client to show progress dialog
//When opening a url or click on link
webView.setWebViewClient(new WebViewClient() {
ProgressDialog progressDialog;
//If you will not use this method url links are opeen in new brower not in webview
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
//Show loader on url load
public void onLoadResource (WebView view, String url) {
if (progressDialog == null) {
// in standard case YourActivity.this
progressDialog = new ProgressDialog(ShowWebView.this);
progressDialog.setMessage("Loading...");
progressDialog.show();
}
}
public void onPageFinished(WebView view, String url) {
try{
if (progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog = null;
}
}catch(Exception exception){
exception.printStackTrace();
}
}
});
// Javascript inabled on webview
webView.getSettings().setJavaScriptEnabled(true);
// Other webview options
/*
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
webView.getSettings().setBuiltInZoomControls(true);
*/
/*
String summary = "<html><body>You scored <b>192</b> points.</body></html>";
webview.loadData(summary, "text/html", null);
*/
//Load url in webview
webView.loadUrl(url);
}
// Open previous opened link from history on webview when back button pressed
@Override
// Detect when the back button is pressed
public void onBackPressed() {
if(webView.canGoBack()) {
webView.goBack();
} else {
// Let the system handle the back button
super.onBackPressed();
}
}
}
现在下面是相应的XML代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
请检查的Android 7.0的代码。希望它可以帮助你!
我抄你的相同的代码和运行的Nexus牛轧糖9应用程序。这需要时间来加载URL等待5分钟,否则与牛轧糖的其他设备进行检查。
public class WebviewMainActivity extends AppCompatActivity {
private WebView wv;
private String webviewURL = "http://stackoverflow.com/questions/41425766/android-7-0-shows-blank-screen-when-trying-to-open-url-in-webview";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview_main);
wv = (WebView) findViewById(R.id.webview);
wv.getSettings().setTextZoom(60);
wv.getSettings().setBuiltInZoomControls(true);
wv.getSettings().setJavaScriptEnabled(true);
wv.loadUrl(webviewURL);
}}
希望这help.Happy coding.Please让我知道,如果它是有帮助的。
我有类似的问题,华硕的Nexus 7,网页视图的版本是56,而Chrome浏览器的应用程序具有较低的版本。我更新后,谷歌Chrome浏览器的应用程序的WebView开始正常工作。
您可以使用loadDataWithBaseURL代替loadData和尝试,我在某些设备上面临着类似的问题。