【问题标题】:Why my URL is not opening in the WebView component?为什么我的 URL 没有在 WebView 组件中打开?
【发布时间】:2021-07-01 20:53:07
【问题描述】:

我必须放置一个聊天 URL 才能在 web 视图中打开,但它无法打开。当我将 URL 更改为 google URL 时,webview 可以正常工作。有谁知道为什么我的 URL 没有打开,而其他的,例如 google 的,打开了吗?

我需要打开的网址是https://www10.directtalk.com.br/chat31/?idd=DDD70036929AA01535BF

 override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)

    chat_webview.webViewClient = object : WebViewClient() {
        override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
            view?.loadUrl(url)
            return true
        }
    }

    chat_webview.apply {
        this.settings.loadsImagesAutomatically = true
        this.scrollBarStyle = View.SCROLLBARS_INSIDE_OVERLAY
        this.settings.useWideViewPort = true
        this.settings.loadWithOverviewMode = true
        this.settings.javaScriptEnabled = true
    }




    firebaseChatURL().addOnSuccessListener {
        chat_webview.loadUrl(it["link"].toString())
    }
}

fun firebaseChatURL(): Task<DocumentSnapshot> =
firestore().document("Settings/chatURL").get()

【问题讨论】:

  • 请同时发布您的代码
  • 对,我贴出来了

标签: android kotlin mobile webview


【解决方案1】:
chat_webview.apply {
    this.settings.loadsImagesAutomatically = true
    this.scrollBarStyle = View.SCROLLBARS_INSIDE_OVERLAY
    this.settings.useWideViewPort = true
    this.settings.loadWithOverviewMode = true
    this.settings.javaScriptEnabled = true
    this.webChromeClient = WebChromeClient() // add this line
}

请先移动上面的代码块然后覆盖 URL,你还没有设置 webview,你期望 webview 覆盖 URL,这就是你的 URL 没有加载的原因。

【讨论】:

  • 我尝试按照您的建议进行操作,但得到了相同的结果。我从 Firebase 获取的 URL 和 webview 所在的 xml 在 onCreateView() 中实例化
  • 你能分享你实际在做什么的要点或代码sn-p吗? @atlas250
猜你喜欢
  • 2021-10-30
  • 1970-01-01
  • 1970-01-01
  • 2017-01-01
  • 1970-01-01
  • 2018-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多