我想在 Webview 加载时加载启动画面。我正在使用下面的代码,但 10 秒后我看到一个黑色的 webview。请帮忙。
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar = (ProgressBar) findViewById(R.id.progressBar1);
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.setVerticalScrollBarEnabled(false);
myWebView.setHorizontalScrollBarEnabled(false);
myWebView.getSettings().setLoadWithOverviewMode(true);
myWebView.getSettings().setUseWideViewPort(true);
myWebView.getSettings().setRenderPriority(RenderPriority.HIGH);
WebView webView = (WebView) findViewById(R.id.webview);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");
myWebView.setWebViewClient(new WebViewClient());
myWebView.setWebViewClient(new MyWebViewClient());
myWebView.loadUrl("http://www.XXXXXXX.com);
setContentView(R.layout.splash);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
private class MyWebViewClient extends WebViewClient {
public void onPageFinished (WebView myWebView, String url) {
setContentView(R.layout.activity_main);
}
}
我希望在加载 webview 时,显示带有应用程序徽标的启动画面。我该怎么做呢 ?我的代码正确吗?一段时间后我得到了 webview,但它似乎是空白的。