繁体   English   中英

加载启动画面直到加载 webview

[英]To load splash screen till webview is loaded

创建了一个 android 应用程序,其中我有一个通过 webview 加载的网站。 我已经让我的启动画面加载了 5 秒,并在中间放置了进度条,以便调整网站加载所需的时间。

现在我需要显示启动画面,直到页面加载完毕并决定删除进度条页面。 我正在使用以下代码。

public class Splashscreen extends Activity {

// Set Duration of the Splash Screen
long Delay = 5000;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Remove the Title Bar
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    // Get the view from splash_activity.xml
    setContentView(R.layout.splash);

    // Create a Timer
    Timer RunSplash = new Timer();

    // Task to do when the timer ends
    TimerTask ShowSplash = new TimerTask() {
        @Override
        public void run() {
            // Close SplashScreenActivity.class
            finish();

            // Start MainActivity.class
            Intent myIntent = new Intent(Splashscreen.this,
                    MainActivity.class);
            startActivity(myIntent);
        }
    };

    // Start the timer
    RunSplash.schedule(ShowSplash, Delay);
}
}

我应该在哪里进行更改?

Splashscreen中时,无法从其他Activity加载WebView 相反,您需要加载MainActivity并将初始屏幕覆盖在WebView

您必须在同一活动中创建启动画面和Web视图。 并且要知道页面何时完成加载,您可以在Webview中使用此方法。

 webview.setWebViewClient(new WebViewClient() {
   @Override
   public void onPageFinished(WebView view, String url) {

    }
});

在onPageFinished()方法中,您可以关闭进度栏

请查看此链接,了解如何在 webview 加载页面之前显示进度条
https://medium.com/android-news/loading-splash-screen-for-webview-in-android-studio-ef68ec05720a

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM