Skip to content
Related Articles
Open in App
Not now

Related Articles

How to Use Custom Chrome Tabs in Android?

Improve Article
Save Article
  • Last Updated : 28 Mar, 2021
Improve Article
Save Article

Many apps have to display different types of webpages inside their application. For displaying webpages in Android there are so many features with which we can display webpages in our Android app. Developers generally prefer to use WebView or redirect users to any browser inside their application. But opening the webpage inside a browser as well as displaying a webpage in Android WebView sometimes becomes a heavy task which we have to perform. Instead of using WebView and opening a webpage in the browser. We can simply use the custom chrome tabs in our application to make this task easier and lighter. Many apps use this feature of custom chrome tabs for redirecting their users from their application to any webpage via custom chrome tabs. So in this article, we will take a look at the implementation of Custom Chrome tabs in Android.

Implementation of Custom Chrome Tabs in Android

Using the Custom Chrome tab we will be simply displaying GFG webpage on a button click in our Android app. A sample GIF is given below from which you will get to know what we are going to do in this article. Note that we are using Java language for the implementation of Chrome tabs in Android.

Custom Chrome Tabs in Android Sample GIF

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Add dependency to build.gradle(Module:app)

Navigate to the Gradle Scripts > build.gradle(Module:app) and add the below dependency in the dependencies section. 

implementation ‘androidx.browser:browser:1.2.0’

Now sync option will appear at the top right corner click on the sync now option.  

Step 3: Working with the activity_main.xml file

Go to the activity_main.xml file and refer to the following code. Below is the code for the activity_main.xml file.


<?xml version="1.0" encoding="utf-8"?>
        android:text="Custom Chrome Tabs" />

Step 4: Working with the file

Go to the file and refer to the following code. Below is the code for the file. Comments are added inside the code to understand the code in more detail.


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.core.content.ContextCompat;
public class MainActivity extends AppCompatActivity {
    Button customChromeTabBtn;
    // url for loading in custom chrome tab
    String url = "";
    protected void onCreate(Bundle savedInstanceState) {
        // initializing button for opening custom chrome tabs.
        customChromeTabBtn = findViewById(;
        customChromeTabBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // initializing object for custom chrome tabs.
                CustomTabsIntent.Builder customIntent = new CustomTabsIntent.Builder();
                // below line is setting toolbar color 
                // for our custom chrome tab.
                customIntent.setToolbarColor(ContextCompat.getColor(MainActivity.this, R.color.purple_200));
                // we are calling below method after 
                // setting our toolbar color.
                openCustomTab(MainActivity.this,, Uri.parse(url));
    public static void openCustomTab(Activity activity, CustomTabsIntent customTabsIntent, Uri uri) {
        // package name is the default package
        // for our custom chrome tab
        String packageName = "";
        if (packageName != null) {
            // we are checking if the package name is not null
            // if package name is not null then we are calling 
            // that custom chrome tab with intent by passing its
            // package name.
            // in that custom tab intent we are passing 
            // our url which we have to browse.
            customTabsIntent.launchUrl(activity, uri);
        } else {
            // if the custom tabs fails to load then we are simply 
            // redirecting our user to users device default browser.
            activity.startActivity(new Intent(Intent.ACTION_VIEW, uri));


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!