Loading...

Android Chrome Custom Tabs Android Tutorial with Example

Android has introduced chrome custom tabs in Marshallow. It is used to load web page/url natively in our android app. Chrome custom tabs provide more control over web experience and to make transition between native application and web content without using WebView. It allows you to customize how chrome looks and feels. You can change the toolbar color, title text hide and show, animation effect and you can add your own action to chrome toolbar and its overflow/dropdown menu. Another important feature of chrome custom tabs is it is faster than WebView and chrome browser.

In this tutorial, you will learn to implement chrome custom tabs in android application. For that you have to add some java code in your activity file and add dependencies in build.gradle file.

Related:
Android Sliding Menu with WebView
Android WebView Tutorial with Example
Simple Android TabHost and TabWidget Example

Android Example: How to Implement Chrome Custom Tabs in Android


Open your app build.gradle file and add compile 'com.android.support:customtabs:23.1.0+' as your project dependencies. Build.gradle file will look like below.

build.gradle

XML Layout File

Open your app XML layout file and add two buttons with onClick attribute. One button to open google.com and another to open viralandroid.com in custom chrome tabs. XML layout file will look like below.

res/layout/chrome_custom_tabs_android_example.xml

Java Activity File

You can control and customize google chrome custom tabs from java activity file. I have added two URLs in button on click event; one viralandroid.com and next one is google.com. If you clicked first button Viral Android website will open in chrome custom tabs and if you click on second button Google search page will open in chrome custom tab. You can change custom tabs toolbar color, overflow menu action and many more. Following is the complete code of java activity file.

src/CustomChromeTabsAndroid.java

Android Example: How to Implement Chrome Custom Tabs in Android

Finally, run your Android Chrome Custom Tabs Android Tutorial with Example application and click on the buttons. If you click on first button viral android website will open in chrome custom tabs. This will look like above screenshot.
WebView 7948287542057004642
Home item