首页 > 解决方案 > Android Webview contentHeight 具有上次访问页面的值

问题描述

当我调用 Webview.contentHeight 时,我每次都会从上次访问的站点中获取值。我该怎么做才能获得新加载网站的 contentHeight ?

我试试这个:

val view = findViewById<WebView>(R.id.view)
url = edit.text.toString()
url = URLUtil.guessUrl(url)
edit.text = url

if (URLUtil.isValidUrl(url)) {
  view.loadUrl(url)
  //here I've tried and give the Webview with sleep(30000) some time, but this also don't working
  var cheight = view.contentHeight
  var vHeight = view.height
  var mheight = view.measuredHeight
  var minheight = view.minimumHeight
  Toast.makeText(this, cheight.toString() + " " + vHeight.toString() + " " + mheight.toString() + " " + minheight.toString(), Toast.LENGTH_SHORT).show()

标签: androidkotlinwebview

解决方案


我不得不解决这个问题。为了测试之后的行为,我在 Button.Listener 中获取 ContentHeight 并使用 Toast.makeText() 显示该值。现在我得到了当前值。


推荐阅读