0

when my webView load this page , it was blank-page or white page only I touch the screen the content can only show

    private WebView webview;
    private ProgressDialog mProgressDialog;
    private Context mContext;
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web);
    mContext = this;
    webview = (WebView)findViewById(R.id.myWebView);
    String url = (String)getIntent().getExtras().get("url");
    webview.getSettings().setJavaScriptEnabled(true);
    webview.setWebViewClient(new MyWebViewClient());
    if(url!=null){
        webview.loadUrl(url);
    }
}
class MyWebViewClient extends WebViewClient {
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
        mProgressDialog = ProgressDialog.show(mContext, "tips", "wate···the view is loading", true, false);
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        mProgressDialog.dismiss();
        super.onPageFinished(view, url);
    }
}

4

2 回答 2

0

以下对我来说很好。试试看。

public class YourHtmlClass extends Activity {

    private WebView mWebview;
    private ProgressDialog progressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.your_layout_containing_webview);
        mWebview = (WebView) findViewById(R.id.webView1);
        WebSettings settings = mWebview.getSettings();
        settings.setJavaScriptEnabled(true);
        mWebview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        progressBar = ProgressDialog.show(AboutUsHtml.this, "", "Loading...",
                true);
        mWebview.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }

            public void onPageFinished(WebView view, String url) {
                if (progressBar.isShowing()) {
                    progressBar.dismiss();
                }
            }

            public void onReceivedError(WebView view, int errorCode,
                    String description, String failingUrl) {
                AlertDialog alert = new AlertDialog.Builder(AboutUsHtml.this)
                        .create();
                alert.setTitle("No connection"));
                alert.setIcon(R.drawable.ic_launcher);
                alert.setCancelable(false);
                alert.setMessage("No connection"));
                alert.setButton("OK", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    }
                });
                alert.show();
            }
        });
        mWebview.loadUrl("Your URL Goes Here");
    }
}
于 2013-11-01T03:42:21.537 回答
0

我猜网址有问题。我尝试使用其他 url 进行 360 度视图并且它有效。检查这个:360度视图

于 2013-11-01T03:25:57.063 回答