Android:即使页面加载完成,进度条也没有消失

时间:2013-12-14 19:40:02

标签: android

即使页面加载完成,

进度条也不会被解雇 我正在尝试在后台加载webview中的URL,以便用户无法识别它是打开的其他网站..我希望他们认为在webview中打开的任何内容都是申请本身。因此,我正在尝试在后台打开网址,直到时间网址加载我想要进度条出现,但是当页面加载我正在解雇进度条但它继续出现..这不是解雇,这就是问题..请帮助我

这是我的代码......

package com.example.urlopeningwithprogressbar;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

ProgressDialog pg;
Background bg;
WebView wv;
Button b1;

static boolean buttonpressed=false;

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    b1=(Button)findViewById(R.id.button1);
    wv = (WebView)findViewById(R.id.webView1);

    b1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            bg = new Background();
            bg.execute();


        }
    });


}
public void progress(){
    pg = new ProgressDialog(MainActivity.this);
    pg.setTitle("");
    pg.setMessage("Please Wait.........");
    pg.setCancelable(false);
    pg.setIndeterminate(true);
    pg.show();
}

class Background extends AsyncTask<Void, Void, Void>
{

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected Void doInBackground(Void... arg0) {
        // TODO Auto-generated method stub


            try{
                wv.loadUrl("URL");
                }catch(Exception e){
                    e.printStackTrace();
                }

                wv.getSettings().setJavaScriptEnabled(true);
                wv.getSettings().setLoadWithOverviewMode(true);
                wv.getSettings().setUseWideViewPort(true);
                wv.getSettings().setBuiltInZoomControls(true);
            //  wv.setWebViewClient(new ourViewClient());



        return null;
    }
    @Override
    protected void onPostExecute(Void result) {

        Toast.makeText(MainActivity.this, "Process Complete", Toast.LENGTH_SHORT).show();


    }

    @Override
    protected void onPreExecute() {
        Toast.makeText(getApplicationContext(), "pre execute is working??", Toast.LENGTH_SHORT).show();
        progress();
    }
}
 public class myWebClient extends WebViewClient
    {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stub
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub

            view.loadUrl(url);
            return true;

        }

        @Override
        public void onPageFinished(WebView view, String url) {
            // TODO Auto-generated method stub
            super.onPageFinished(view, url);

            pg.dismiss();
        }
    }

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

1 个答案:

答案 0 :(得分:2)

您永远不会实例化或使用您的myWebClient课程。 你必须

wv.setWebViewClient(new myWebClient()); 

实际使用它。 另请注意,类名应为大写。