我有一个“启动画面”显示,直到webview加载到我的应用程序中。
启动是“ImageView”。对于“onPageStarted”是可见的,在“onPageFinished”之后,imageview是GONE,Webview是可见的。
它在我的星系3s 4.3上工作得很好但是在Galaxy 5s上4.4.2 kitkat它加载没有图像的app。
问题在哪里!?
这是我的main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="fill"
android:id="@+id/rel_webpage_whole"
android:background="#000000"
>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
android:visibility="gone"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/splashload"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:visibility="visible"
android:background="#ffffffff" />
</RelativeLayout>
和MainActivity.java:
package com.com.myapplication;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.webkit.JsResult;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.Toast;
import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webView = (WebView) findViewById(R.id.webview);
String url="http://www.google.com";
initWebView(webView,url);
// TODO input your url
}
private final static Object methodInvoke(Object obj, String method, Class<?>[] parameterTypes, Object[] args) {
try {
Method m = obj.getClass().getMethod(method, new Class[] { boolean.class });
m.invoke(obj, args);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private void initWebView(WebView view, String url) {
WebSettings settings = view.getSettings();
final WebView myWebView = (WebView) findViewById(R.id.webview);
final ImageView imageView = (ImageView) findViewById(R.id.imageView); // i add this maybe this a problem
view.setWebViewClient(new WebViewClient());
settings.setJavaScriptEnabled(true);
settings.setAllowFileAccess(true);
settings.setDomStorageEnabled(true);
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setSupportZoom(true);
// settings.setPluginsEnabled(true);
methodInvoke(settings, "setPluginsEnabled", new Class[] { boolean.class }, new Object[] { true });
// settings.setPluginState(PluginState.ON);
methodInvoke(settings, "setPluginState", new Class[] { PluginState.class }, new Object[] { PluginState.ON });
// settings.setPluginsEnabled(true);
methodInvoke(settings, "setPluginsEnabled", new Class[] { boolean.class }, new Object[] { true });
// settings.setAllowUniversalAccessFromFileURLs(true);
methodInvoke(settings, "setAllowUniversalAccessFromFileURLs", new Class[] { boolean.class }, new Object[] { true });
// settings.setAllowFileAccessFromFileURLs(true);
methodInvoke(settings, "setAllowFileAccessFromFileURLs", new Class[] { boolean.class }, new Object[] { true });
view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
view.clearHistory();
view.clearFormData();
view.clearCache(true);
view.loadUrl(url);
view.setWebViewClient(new WebViewClient() {
ProgressDialog dialog = new ProgressDialog(MainActivity.this);
@Override
public void onPageStarted(WebView view, String url,
Bitmap favicon) {
// TODO Auto-generated method stub
dialog.setMessage("loading...");
dialog.show();
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
myWebView.setVisibility(View.VISIBLE);
imageView.setVisibility(View.GONE); // i add this maybe this a problem
dialog.dismiss();
super.onPageFinished(view, url);
}
});
view.setWebChromeClient(new MyWebChromeClient());
// webView.setDownloadListener(downloadListener);
}