Skip to content

Instantly share code, notes, and snippets.

@ThomasGorisse
Created January 21, 2022 14:05
Show Gist options
  • Select an option

  • Save ThomasGorisse/c155ace2a11a2e952f142ba3bf6e2cf3 to your computer and use it in GitHub Desktop.

Select an option

Save ThomasGorisse/c155ace2a11a2e952f142ba3bf6e2cf3 to your computer and use it in GitHub Desktop.
class WebView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = 0
) : WebView(context, attrs, defStyleAttr, defStyleRes) {
init {
this.isScrollContainer = false
this.isNestedScrollingEnabled = false
this.setBackgroundColor(Color.TRANSPARENT)
this.webViewClient = WebViewClient()
}
class WebViewClient : android.webkit.WebViewClient() {
override fun shouldOverrideUrlLoading(
view: WebView?,
request: WebResourceRequest
): Boolean {
return if (request.url.scheme?.startsWith("http") == true) {
application.open(url = request.url.toString())
true
} else {
super.shouldOverrideUrlLoading(view, request)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment