Custom Chrome Tabs You can see sample code from Google Chrome here .
Try using the following utility class:
public class CustomTabs { private static final int TOOLBAR_SHARE_ITEM_ID = 1; public static void openTab(Context context, String url) { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); enableUrlBarHiding(builder); setToolbarColor(context, builder); setSecondaryToolbarColor(context, builder); setCloseButtonIcon(context, builder); setShowTitle(builder); setAnimations(context, builder); setShareActionButton(context, builder, url); addToolbarShareItem(context, builder, url); addShareMenuItem(builder); addCopyMenuItem(context, builder); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.launchUrl(context, Uri.parse(url)); } private static void enableUrlBarHiding(CustomTabsIntent.Builder builder) { builder.enableUrlBarHiding(); } private static void setToolbarColor(Context context, CustomTabsIntent.Builder builder) { builder.setToolbarColor(ContextCompat.getColor(context, R.color.colorPrimary)); } private static void setSecondaryToolbarColor(Context context, CustomTabsIntent.Builder builder) { builder.setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.colorPrimary)); } private static void setCloseButtonIcon(Context context, CustomTabsIntent.Builder builder) { builder.setCloseButtonIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_arrow_back)); } private static void setShowTitle(CustomTabsIntent.Builder builder) { builder.setShowTitle(true); } private static void setAnimations(Context context, CustomTabsIntent.Builder builder) { builder.setStartAnimations(context, R.anim.slide_in_right, R.anim.slide_out_left); builder.setExitAnimations(context, R.anim.slide_in_left, R.anim.slide_out_right); } private static void setShareActionButton(Context context, CustomTabsIntent.Builder builder, String url) { Bitmap icon = BitmapFactory.decodeResource(context.getResources(), android.R.drawable.ic_menu_share); String label = "Share via"; Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_TEXT, url); shareIntent.setType("text/plain"); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, shareIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setActionButton(icon, label, pendingIntent); } private static void addToolbarShareItem(Context context, CustomTabsIntent.Builder builder, String url) { Bitmap icon = BitmapFactory.decodeResource(context.getResources(), android.R.drawable.ic_menu_share); String label = "Share via"; Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_TEXT, url); shareIntent.setType("text/plain"); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, shareIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.addToolbarItem(TOOLBAR_SHARE_ITEM_ID, icon, label, pendingIntent); } private static void addShareMenuItem(CustomTabsIntent.Builder builder) { builder.addDefaultShareMenuItem(); } private static void addCopyMenuItem(Context context, CustomTabsIntent.Builder builder) { String label = "Copy"; Intent intent = new Intent(context, CopyBroadcastReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.addMenuItem(label, pendingIntent); } public static class CopyBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String url = intent.getDataString(); ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData data = ClipData.newPlainText("Link", url); clipboardManager.setPrimaryClip(data); Toast.makeText(context, "Copied " + url, Toast.LENGTH_SHORT).show(); } } }
Remember to add dependencies to app/build.gradle
dependencies { ... compile 'com.android.support:customtabs:25.2.0' }
and register your BroadcastReceiver in AndroidManifest.xml
<application> ... <receiver android:name=".CustomTabs$CopyBroadcastReceiver" /> </application>