Java Android webview闪屏不会消失

Java Android webview闪屏不会消失,java,android,xml,webview,splash-screen,Java,Android,Xml,Webview,Splash Screen,我按照这里关于在webview上放置闪屏的回答,我得到了它现在出现在我的应用程序上的观点,但现在它不像预期的那样出现了。当我注释掉启动屏幕时,该站点的负载刚刚好 我认为java file-onCreate是我感兴趣的地方 package com.emman.app; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; impo

我按照这里关于在webview上放置闪屏的回答,我得到了它现在出现在我的应用程序上的观点,但现在它不像预期的那样出现了。当我注释掉启动屏幕时,该站点的负载刚刚好

我认为java file-onCreate是我感兴趣的地方

package com.emman.app;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.ProgressBar;


public class MainActivity extends Activity {

    private WebView mWebView;
    ImageView imgLoading;
    ProgressBar bar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mWebView = (WebView) findViewById(R.id.activity_main_webview);
        imgLoading = (ImageView)findViewById(R.id.imgloader);
         bar = (ProgressBar) findViewById(R.id.progressBar1);
        // Enable Javascript
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        // Force links and redirects to open in the WebView instead of in a browser
        mWebView.setWebViewClient(new WebViewClient() {

            @Override
            public void onPageFinished(WebView view, String url) {
             //   super.onPageFinished(view, url); commented out not fix
                //hide loading image
                imgLoading.setVisibility(View.GONE);
                bar.setVisibility(View.GONE);
                //show webview
                mWebView.setVisibility(View.VISIBLE);
            }


        });

        // Use remote resource
        mWebView.loadUrl("http://8ch.net");

        // Stop local links and redirects from opening in browser instead of WebView
         mWebView.setWebViewClient(new MyAppWebViewClient());

        // Use local resource
      //   mWebView.loadUrl("file:///android_asset/www/index.html");
    }

    // Prevent the back-button from closing the app
    @Override
    public void onBackPressed() {
        if(mWebView.canGoBack()) {
            mWebView.goBack();
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
            case R.id.action_settings:
                finish();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
       /* // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }*/
    }
}
xml文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/imgloader"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/splash"
        android:visibility="visible" />

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="101dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:visibility="visible"/>

    <WebView
        android:id="@+id/activity_main_webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone" />

</RelativeLayout>

请在评论后检查

setWebViewClient(新的MyAppWebViewClient())

根据我的说法,你必须在主线程上启动一个新线程,在主线程中显示加载图像,然后在主线程中加载网站。另外,将进度条与网页加载状态同步