gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 21:22:19 25 4
gpt4 key购买 nike

即使页面加载完成,进度条也不会消失我正在尝试在后台加载 webview 中的 url,以便用户无法识别它是打开的其他网站。我希望他们认为 webview 中打开的任何内容都是应用程序本身。因此,我试图在后台打开 url,直到加载 url 时,我希望进度条出现,但是当页面加载时,我正在关闭进度条,但它继续出现。它没有关闭,这就是问题所在。请帮帮我

这是我的代码...

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;
}

最佳答案

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

wv.setWebViewClient(new myWebClient()); 

实际使用它。还要注意类名应该是大写的。

关于Android:即使页面加载完成,进度条也不会消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20587420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com