android webview displaying blank page

后端 未结 14 808
借酒劲吻你
借酒劲吻你 2020-12-14 06:33

I have an android application that I am developing using the emulator running on android 2.3.3 with an embedded WebView in a framelayout nested in a linearlayout (vertical).

相关标签:
14条回答
  • In my case, it was due to the fact that my webview was attempting to load a page using HTTPS where the certificate was untrusted.

    You can check if this is the case in your code using the following snippet:

    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
        handler.proceed();
    }
    

    Java

    override fun onReceivedSslError(view: WebView?, handler: SslErrorHandler?, error: SslError?) {
        handler?.proceed()
    }
    

    Kotlin

    Then, if it is the case, quickly remove the snippet and refer to the documentation to diagnose the problem further and potentially add the certificate to your keystore.

    0 讨论(0)
  • 2020-12-14 06:53

    If it still Doesn't work then please try adding "http://" or "https://" before the web address and it should work.

    0 讨论(0)
  • 2020-12-14 06:57
    WebSettings settings = wbView.getSettings();
    settings.setDomStorageEnabled(true);
    
    0 讨论(0)
  • 2020-12-14 06:57

    My webview was displaying a white blank square on top of it, sometimes totally blank. This only occurred when it was loading certain data.

    Changing it to a RelativeLayout, and setting layout_height to match_parent worked for me.

    <RelativeLayout xmlns:android=...
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <RelativeLayout
            android:id="@+id/ll_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginTop="3dp"
            android:gravity="center_vertical"
            android:orientation="horizontal">
    
            .....
    
        </RelativeLayout>
    
        <WebView
            android:id="@+id/web_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/ll_title"
            android:background="@color/colorYellow" />
    
    
        <ProgressBar
            android:id="@+id/pb_spinning"
            style="?android:attr/progressBarStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:visibility="gone" />
    
    </RelativeLayout>
    
    0 讨论(0)
  • 2020-12-14 06:59

    It might be a bit too late, but I wanted to share my experience with you, because I had the same problem and spent a lot of time on it.

    Put your WebView in RelativeLayout and not in FrameLayout.

    What I have tested: My WebView's onPageFinished() was called every time, but on the screen I got blank page.

    From chrome://inspect WebView debugger I was able to "ping" my WebView by pressing inspect button, and after that WebView was refreshing immediately.

    My thoughts - WebView isn't rendered correctly in FrameLayout, and RelativeLayout fixes the issue (even invalidate() and requestLayout() calls didn't help).

    0 讨论(0)
  • 2020-12-14 06:59

    instead of passing null, you should pass an empty String to it. ex: ""
    So you should call it like this:
    wview.loadDataWithBaseURL("", "<HTML><BODY><H3>Test</H3></BODY></HTML>","text/html","utf-8","");

    0 讨论(0)
提交回复
热议问题