简单地说我怎样才能使每一个新的链接被点击我的的WebView
时间进度对话框显示出来。我试过很多教程和方法,但他们每个人只显示对话框一次,当应用程序最初加载。
下面是我的code
mWebView.setWebViewClient(新WebViewClient(){
@覆盖
公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL)
{
view.loadUrl(URL);
返回true;
}
ProgressDialog对话框= ProgressDialog.show(myActivity.this,,
Loading请稍候......,真正的);
@覆盖
公共无效onPageFinished(web视图查看,字符串URL){
dialog.dismiss();
}
解决方案
试试这个,
//让显示在活动标题栏中的进步,像
//浏览器的应用程序一样。
。getWindow()requestFeature(Window.FEATURE_PROGRESS);
webview.getSettings()setJavaScriptEnabled(真)。
最后活动活动=这一点;
webview.setWebChromeClient(新WebChromeClient(){
公共无效onProgressChanged(web视图来看,INT进度){
//活动和不同规模WebViews措施的进展。
//当我们达到100%,进度条会自动消失
activity.setProgress(进度* 1000);
}
});
webview.setWebViewClient(新WebViewClient(){
公共无效onReceivedError(web视图来看,INT错误code,字符串描述,字符串failingUrl){
Toast.makeText(活动,哦,不!+描述,Toast.LENGTH_SHORT).show();
}
});
webview.loadUrl(http://slashdot.org/);
如果你想使自己的progressDialog然后
webView.setWebViewClient(新WebViewClient(){
@覆盖
公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL)
{
//开始进度对话框
view.loadUrl(URL);
返回true;
}
@覆盖
公共无效onPageFinished(web视图查看,字符串URL){
//隐藏进度对话框加载完毕
}
});
和让我知道发生什么事。
Simply put how can I make a progress dialog show up every time a new link is clicked in my webview
. I have tried many tutorials and methods but every one of them only shows the dialog once, when the app is initially loaded.
Here is my code
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
ProgressDialog dialog = ProgressDialog.show(myActivity.this, "",
"Loading. Please wait...", true);
@Override
public void onPageFinished(WebView view, String url) {
dialog.dismiss();
}
解决方案
Try this,
// Let's display the progress in the activity title bar, like the
// browser app does.
getWindow().requestFeature(Window.FEATURE_PROGRESS);
webview.getSettings().setJavaScriptEnabled(true);
final Activity activity = this;
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
activity.setProgress(progress * 1000);
}
});
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
webview.loadUrl("http://slashdot.org/");
And if you want to make your own progressDialog then
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
// Start PROGRESS DIALOG
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
//HIDE PROGRESS DIALOG LOADING IT HAS FINISHED
}
});
And let me know what happen..