PhoneGap(更具体地说是适用于 Android 的 DroidGap)是否有办法判断其 webview 何时加载。我想为 PhoneGap 找到类似以下的内容:
正常 WebView 客户端创建:
mWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
// do your stuff here
}
});
像这样创建我的 PhoneGap Webview:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity);
if (isOnline() == true) {
WebSettings settings = mWebView.getSettings();
settings.setAllowFileAccess(true);
settings.setAppCacheEnabled(true);
settings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://myurl.com");
mWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
//hide loading image
findViewById(R.id.imageLoading1).setVisibility(View.GONE);
//show webview
findViewById(R.id.mWebView).setVisibility(View.VISIBLE);
}
});
}
else {
//hide loading image
findViewById(R.id.imageLoading1).setVisibility(View.GONE);
//show webview
findViewById(R.id.mWebView).setVisibility(View.VISIBLE);
Intent myIntent = new Intent(getContext(), LoadScreen.class);
startActivity(myIntent);
finish();
}
}
我的 Main_Activity.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" >
<ImageView android:id="@+id/imageLoading1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:visibility="visible"
android:src="@drawable/splash"
/>
<WebView android:id="@+id/mWebView"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:visibility="gone"
/>
</RelativeLayout>