Android Chrome Custom Tabs WebView
CustomTabs is a game-changer when it comes to handling or linking to a certain URL in your android application. Android CustomTabs are more reliable when it comes to a smooth and fast loading of URLs inside your application.
The Android CustomTabs android library will provide you with all the necessary function for implementing a custom tab in your android application. The library is developed using Kotlind and Shell. The library reduces the development time for any android application as it allows a better and efficient way of running URLs inside the android application.
The Android CustomTabs has simplified the process of showcasing the Custom tabs for developers. This library has aimed to make the development process easier. One of the functions of the library is that it allows a pre-load for custom tab and fallback in case of Chrome not being available.
So, let us get right into the steps of using the Android CustomTabs in the application:
This code will show how to create a new custom tab intent and start it with a keep-alive service. Also, it uses fallback for a plain old WebView in case of Chrome not being available:
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
.addDefaultShareMenuItem()
.setToolbarColor(this.getResources().getColor(R.color.colorPrimary))
.setShowTitle(true)
.setCloseButtonIcon(backArrow)
.build();
// This is optional but recommended
CustomTabsHelper.addKeepAliveExtra(this, customTabsIntent.intent);
// This is where the magic happens...
CustomTabsHelper.openCustomTab(this, customTabsIntent,
Uri.parse("https://github.com/saschpe/android-customtabs"),
new WebViewFallback());
// Preload custom tabs service for improved performance
// This is optional but recommended
registerActivityLifecycleCallbacks(new CustomTabsActivityLifecycleCallbacks());
Screenshots
Download
compile 'saschpe.android:customtabs:2.0.0'
snapshots
repository.