Skip to content

Instantly share code, notes, and snippets.

@sembozdemir
Created December 19, 2017 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sembozdemir/1e2e44f7f13bfdb4ac2ae2ef763af59d to your computer and use it in GitHub Desktop.
Save sembozdemir/1e2e44f7f13bfdb4ac2ae2ef763af59d to your computer and use it in GitHub Desktop.
CustomTabs (android.support.customtabs) extensions for Kotlin
import android.app.Fragment
import android.content.Context
import android.net.Uri
import android.support.customtabs.CustomTabsIntent
import android.support.v4.content.ContextCompat
import android.support.v4.app.Fragment as SupportFragment
fun Context.customTab(url: String, init: (CustomTabsIntent.Builder.() -> Unit)? = null) {
val customTabBuilder = CustomTabsIntent.Builder()
.addDefaultShareMenuItem()
.setShowTitle(true)
// other default settings for your custom tabs.
init?.let { customTabBuilder.init() }
customTabBuilder.build().launchUrl(this, Uri.parse(url))
}
fun Fragment.customTab(url: String, init: (CustomTabsIntent.Builder.() -> Unit)? = null) {
activity.customTab(url, init)
}
fun SupportFragment.customTab(url: String, init: (CustomTabsIntent.Builder.() -> Unit)? = null) {
activity.customTab(url, init)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment