显示 Android WebView 的图标
我想显示我通过 android.webkit.WebView 访问的网站的图标。我尝试了两种方法来获取它:
1) WebViewClient.onPageStarted()
方法有一个始终为空的 favicon 参数。
2) WebChromeClient.onReceivedIcon()
方法永远不会被调用。
3)在onPageStarted()
和onPageFinished()
中调用WebView.getFavicon()
但总是返回null。
我无法在网上找到显示如何访问图标的示例。任何提示将不胜感激。
I'd like to display the favicon of the website I am accessing via the android.webkit.WebView. I've tried two ways to get it:
1) WebViewClient.onPageStarted()
method has a favicon parameter that is always null.
2) WebChromeClient.onReceivedIcon()
method is never called.
3) Called WebView.getFavicon()
in onPageStarted()
and onPageFinished()
but it always returns null.
I haven't been able to find an example online that shows how to access the favicon. Any hints would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了使 WebView 图标方法和侦听器正常工作,您需要首先手动打开 WebIconDatabase。您通常会在 Activity 的
onCreate()
方法中执行此操作。尝试将以下行添加到
onCreate()
中:完成此操作后,您应该开始获取此 Activity 中任何 WebView 的
onReceivedIcon()
回调,并且getFavicon() 方法还应该开始返回有效对象而不是 null。
For the WebView icon methods and listeners to work, you need to first open the WebIconDatabase manually. You would typically do this in the
onCreate()
method of your Activity.Try adding the following line to
onCreate()
:Once you've done this, you should start getting
onReceivedIcon()
callbacks for any WebView in this Activity, and thegetFavicon()
method should also start returning a valid object rather than null whenever icons are available.我想请记住,有一个方法
getFavicon()
可用于 WebView 对象。这是我的愚蠢问题你尝试过吗?I think to remember that there is a method
getFavicon()
available for the WebView object. here is my stupid question did you try that?