Created
January 21, 2022 14:05
-
-
Save ThomasGorisse/c155ace2a11a2e952f142ba3bf6e2cf3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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