Loading...

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.


How To Use

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());
For preloding CustomTabs in you application(.java), this code will make sure the CustomTabs are ready to use and reduce the start-up time:
// Preload custom tabs service for improved performance
// This is optional but recommended
registerActivityLifecycleCallbacks(new CustomTabsActivityLifecycleCallbacks());

Screenshots

For a quick glimpse on how the library manages to produce the customTab and preload the contents, you can rely on the images provided below:
Screenshot 1
Screenshot 2
Screenshot 3

Download

compile 'saschpe.android:customtabs:2.0.0'
Snapshots of the development version are available in Sonatype's snapshots repository.

Download complete project source code from GitHub
WebView 4155398385339322665
Home item