Chrome Custom Tabs gives apps more control over their web experience and make transitions between native and web content more seamless without having to resort to a WebView.
Chrome Custom Tabs allow an app to customize how Chrome looks and feels. An app can change things like:
- Toolbar color
- Enter and exit animations
- Add custom actions to the Chrome toolbar, overflow menu and bottom toolbar
Chrome Custom Tabs also allow the developer to pre-start Chrome and pre-fetch content for faster loading.
To use custom chrome tab in Android, you first need to include the following dependency in your build grade file.
compile 'com.android.support:customtabs:23.4.0+'
Sync the project after adding the dependencies. Now you’re good to go.
public static void launchChromeTab(Activity activity, String url) { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); builder.setToolbarColor(ContextCompat.getColor(activity, R.color.colorPrimary)); builder.setSecondaryToolbarColor(ContextCompat.getColor(activity, R.color.colorPrimaryDark)); // set start and exit animations builder.setStartAnimations(activity, R.anim.slide_in_right, R.anim.slide_out_left); builder.setExitAnimations(activity, android.R.anim.slide_in_left, android.R.anim.slide_out_right); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.launchUrl(activity, Uri.parse(url)); }