WebView 加载后无法让 ProgressDialog 停止
我可以显示 ProgressDialog,但在加载 WebView 后无法让它停止。我所需要的只是一个简单的刷新按钮。
这是到目前为止的工作代码:
public class Quotes extends Activity implements OnClickListener{
WebView webview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.scroll);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://www.dgdevelco.com/quotes/quotesandroid.html");
View refreshClick = findViewById(R.id.refresh);
refreshClick.setOnClickListener(this);
}
public void onClick(View v){
switch(v.getId()){
case R.id.refresh:
ProgressDialog.show(Quotes.this, "", "Loading...", true);
webview.reload();
}
}
}
我只是想不通。我到处都看过,但似乎没有任何效果。
I can get the ProgressDialog to show, but I cannot get it to stop after the WebView has been loaded. All I need is a simple refresh button for it.
Here is the working code so far:
public class Quotes extends Activity implements OnClickListener{
WebView webview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.scroll);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://www.dgdevelco.com/quotes/quotesandroid.html");
View refreshClick = findViewById(R.id.refresh);
refreshClick.setOnClickListener(this);
}
public void onClick(View v){
switch(v.getId()){
case R.id.refresh:
ProgressDialog.show(Quotes.this, "", "Loading...", true);
webview.reload();
}
}
}
I just can't figure it out. I've looked everywhere but nothing seems to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是快速答案,您应该真正为 WebViewClient 实现您自己的类,您也应该在该类中显示对话框,但您会弄清楚的。
首先,使您的对话框全局化(在您的实际应用程序中,您可能希望将其传递给您的客户端,或在 webviewclient 中声明它,然后也覆盖 onPageStarted)。
然后简单地说:
这是您需要的API: WebViewClient
编辑
好的这让我很恼火,这是正确的方法:
新课程:
Right this is the quick answer, you should really implement your own class for the WebViewClient, you should show the dialog in that class as well but you'll figure that out.
First, make your dialog global, (in your real app you might want to pass it in to your client, or declare it in the webviewclient, then override on onPageStarted as well).
then simply:
This is the API you need: WebViewClient
EDIT
Ok it was annoying me, here is the proper way:
The new class: