Created
December 19, 2017 12:03
-
-
Save sembozdemir/1e2e44f7f13bfdb4ac2ae2ef763af59d to your computer and use it in GitHub Desktop.
CustomTabs (android.support.customtabs) extensions for Kotlin
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
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