android webview启动画面应用程序无法正常工作

时间:2014-01-15 07:56:57

标签: android web splash

您好我正在使用Android app.I刚刚创建了一个带有启动画面和进度条的Web视图。最初启动了启动画面,然后进度条工作,同时Web URL加载在后台。加载启动画面完成后没有被解雇。所以我看不到网页。怎么解决这个???

这是我的代码

        public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          requestWindowFeature(Window.FEATURE_NO_TITLE); 
          setContentView(R.layout.main);
          this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
       if(isNetworkStatusAvialable (getApplicationContext())) {
        mWebView = (WebView) findViewById(R.id.webview);
         progressBar = (ProgressBar) findViewById(R.id.progressBar1);
         image =(ImageView)findViewById(R.id.image);
         progressBar.setMax(100);

            mWebView.getSettings().setJavaScriptEnabled(true);
            mWebView.setWebViewClient(new wapWebViewClient());
            mWebView.loadUrl("http://facebook.com/");
            mWebView.setWebViewClient(new WebViewClient()
              {
                 @Override
                 public void onPageFinished(WebView view, String url) 
                 {
                    super.onPageFinished(view, url);
                   //here dismiss your splash
                 }
              });
            mWebView.setWebChromeClient(new WebChromeClient() {
                @Override
                public void onProgressChanged(WebView view, int progress) 
                   {
                   if(progress < 100 && progressBar.getVisibility() == View.GONE){
                       progressBar.setVisibility(View.VISIBLE);
                   }
                   progressBar.setProgress(progress);
                   if(progress == 100) {
                       progressBar.setVisibility(View.GONE);
                   }
                }
            });


         } else {
           Toast.makeText(getApplicationContext(), "internet is not avialable ", Toast.LENGTH_LONG).show();

          }
            ImageButton imageButton1 = (ImageButton) findViewById(R.id.imageButton1);
           ImageButton  imageButton2 = (ImageButton) findViewById(R.id.imageButton2);

         imageButton1.setOnClickListener(new OnClickListener() {


       public void onClick(View v) {

                Intent feedbackEmail = new Intent(Intent.ACTION_SEND);

                feedbackEmail.setType("text/email");
               feedbackEmail.putExtra(Intent.EXTRA_EMAIL, new String[] {"prince@gmail.com"});
             feedbackEmail.putExtra(Intent.EXTRA_SUBJECT, "Feedback");
           startActivity(Intent.createChooser(feedbackEmail, "Send Feedback:"));
        }
       });

       imageButton2.setOnClickListener(new OnClickListener() {


       public void onClick(View v) {
              View popUpView = getLayoutInflater().inflate(R.layout.popup, null); // inflating popup layout
              mpopup = new PopupWindow(popUpView, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, true); //Creation of popup

                mpopup.showAtLocation(popUpView, Gravity.BOTTOM, 0, 0);    // Displaying popup
               ImageButton Sub = (ImageButton) popUpView.findViewById(R.id.submit);     
                Sub.setOnClickListener(new OnClickListener() {


            public void onClick(View v) {
                  mpopup.dismiss();

            }
        }); 
       }  
       });

           }

        private void incrementPercentage(){
       int mProgressStatus=0;
        mProgressStatus++;//i declared it as a private Integer on the activity class.
      progressBar.setProgress(mProgressStatus);
    }



       public static boolean isNetworkStatusAvialable (Context context) {
          ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivityManager != null) 
      {
           NetworkInfo netInfos = connectivityManager.getActiveNetworkInfo();
           if(netInfos != null)
           if(netInfos.isConnected()) 
            return true;
       }
       return false;
      }

         private class wapWebViewClient extends WebViewClient {

      @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
      view.loadUrl(url);
             return true;
          }

      @Override
     public void onPageFinished(WebView view, String url) {
      // when the page loaded splash screen has been invisible
      mWebView.setVisibility(View.VISIBLE); 
      progressBar.setVisibility(View.GONE);
      image.setVisibility(View.GONE);

      }

       @Override
    public void onReceivedError(WebView view, int errorCode,
            String description, String failingUrl) {
        // if any error occured this message will be showed
                 Toast.makeText(WebViewExample.this, "Error is occured, please try again..." + description, Toast.LENGTH_LONG).show();
    }
        }

       @Override
     public boolean onKeyDown(int keyCode, KeyEvent event) {
     if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
      // setting of back button
      mWebView.goBack();
         return true;
      }
      return super.onKeyDown(keyCode, event);
       }
       }

2 个答案:

答案 0 :(得分:2)

您可以覆盖WebViewClient的方法并在加载页面时关闭启动

webView.setWebViewClient(new WebViewClient()
      {
         @Override
         public void onPageFinished(WebView view, String url) 
         {
            super.onPageFinished(view, url);
           //here dismiss your splash
         }
      });

答案 1 :(得分:1)

使用setWebViewClient()并覆盖onPageFinished()并隐藏您的进度条或启用此方法。