有没有办法通知用户等待WebView加载图像

发布于 2024-12-26 12:03:24 字数 125 浏览 2 评论 0原文

我的活动中有 WebView,我需要在该 webview 中加载一些本地字符串( html )。问题是本地 html 包含来自远程服务器的图像,因此需要时间下载和显示。有没有办法通知用户等待,比如旋转对话框之类的?如何通知用户等待内容?

I have WebView in my activity and I need to load some local string ( html ) in that webview. Problem is that local html contains images from remoted servers so it needs time to download and show. Is there way to notify user to wait, like spinning dialog or something ? How to notify user to wait content ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

萌逼全场 2025-01-02 12:03:24

没有内置功能可以满足您的需要。

但是,您可以设置 WebViewClient WebView(请参阅webView.setWebViewClient()) 并重写方法 onPageStarted()onPageFinished ()。通过这种方式,您可以显示 ProgressDialog或其他进度指示器(使用 RotateAnimation 例如)当页面已开始加载,并在页面完成加载后将其关闭。

webView.setWebViewClient(new WebViewClient(){
  public void onPageStarted(WebView view, String url, Bitmap favicon){
    //show progress indicator
  }

  public void onPageFinished(WebView view, String url){
    //hide progress indicator
  }
});

There is not built-in function for doing what you need.

However, you can set a WebViewClient on WebView (see webView.setWebViewClient()) and override the methods onPageStarted() and onPageFinished(). In this way you can show a ProgressDialog or other progress indicator (use a RotateAnimation for example) when the page has started loading and dismiss it later when the page has finished loading.

webView.setWebViewClient(new WebViewClient(){
  public void onPageStarted(WebView view, String url, Bitmap favicon){
    //show progress indicator
  }

  public void onPageFinished(WebView view, String url){
    //hide progress indicator
  }
});
感受沵的脚步 2025-01-02 12:03:24

您可以使用 css 在 html 页面中执行此操作或 javascript

You could do that in your html page using css or javascript.

何时共饮酒 2025-01-02 12:03:24

您可以为 webview 设置 webviewCLient ,您将在 PageFinished 上收到回调。

You could set a webviewCLient to the webview and you will get callback onPageFinished.

扛刀软妹 2025-01-02 12:03:24

ts 在所有设备上正常工作使用此链接:- 加载 Web 视图进度对话框

ts working fine on all devices Use this link :- Load Web View ProgressDialog

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文