感謝您試圖解決我的問題!XML初始屏幕 - >顯示Webview
目前我的應用程序基本上使用Android Web視圖加載網頁。缺點是有時(連接不好)網頁需要10秒以上才能加載。有什麼辦法可以在網頁加載時創建某種形式的XML「加載」屏幕?
看看我的代碼...
package com.ect;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.CookieSyncManager;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class SomeActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//THIS IS WHAT I WANT: setContentView(R.layout.main);
CookieSyncManager.createInstance(getBaseContext());
// Let's display the progress in the activity title bar, like the
// browser app does.
getWindow().requestFeature(Window.FEATURE_PROGRESS);
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
final Activity activity = this;
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
activity.setProgress(progress * 1000);
}
});
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
//Users will be notified in case there's an error (i.e. no internet connection)
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
public void onPageFinished(WebView view, String url) {
CookieSyncManager.getInstance().sync();
}
});
CookieSyncManager.getInstance().startSync();
CookieSyncManager.getInstance().sync();
//This will load the webpage that we want to see
webview.loadUrl("http://www.web.com/");
}
}
這是我的代碼。如果仔細觀察,我發表了一條評論:「這是我想要的內容:...」
該評論會調用要顯示的main.xml文件,但如果我使用該評論,main.xml文件將顯示,但webview從不出現...
如何顯示main.xml文件,然後(一旦web視圖加載)顯示網頁?
感謝Piperoman!我完全不熟悉用Android進行開發......有什麼辦法可以給我一些代碼嗎? – Joe 2011-12-21 17:06:20