Android webview显示白色屏幕而不是加载网站。当我从网络浏览器打开它时,网站完全打开,我正在使用以下代码这里是代码,请帮助我,我能做些什么呢?
AndroidMainifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.aditya.aditya">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:debuggable="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml中
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/webView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</android.support.constraint.ConstraintLayout>
MainActivity.java
包in.aditya.aditya;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
private WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview =(WebView)findViewById(R.id.webView);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
webview.loadUrl("https://www.pdf2jpg.net");
}
}
答案 0 :(得分:0)
您可以使用webview.setWebViewClient()方法检查是否正在加载网址。它有覆盖方法,如 onPageFinished(), onPageStarted()等...... !!
尝试以下代码:
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
Log.d("Log-->> ", "onPageStarted: ");
}
public void onPageFinished(WebView view, String url) {
Log.d("Log-->> ", "onPageFinished: ");
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
Log.d("Log-->> ", "onReceivedError: ");
}
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
super.onReceivedHttpError(view, request, errorResponse);
Log.d("Log-->> ", "onReceivedHttpError: ");
}
});
您可以查看日志以查看您的网址是否正确加载。
答案 1 :(得分:0)
确保您已在清单中添加了互联网权限
并检查系统android webview是否更新。早些时候发现了一些问题,如空白页