Search code examples
androidchrome-custom-tabs

Chrome custom tab shows action button outside the toolbar


I want to add an action button to ChromeCustomTabs' toolbar so I followed this tutorial

The button is added but, instead of appearing in the toolbar, it appears at the bottom of the activity:

ChromeCustomTab

This is the code I use to create the Chrome Custom Tab:

private static void openUrlInChromeCustomTab(String webUrl, Activity activity, Item item) {
    if (!(webUrl.startsWith("http:") || webUrl.startsWith("https:"))) {
        webUrl = "http://" + webUrl;
    }

    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();

    Bitmap largeIcon = BitmapFactory.decodeResource(activity.getResources(), R.drawable.ic_share);

    Product product = (Product) item;

    PendingIntent pendingIntent;
    Intent intent = new Intent();
    intent.setClass(activity, SharingDummyActivity.class);

    Bundle bundle = new Bundle();
    bundle.putSerializable(SharingDummyActivity.PRODUCT_CRITERIA, product);
    intent.putExtras(bundle);

    pendingIntent =  PendingIntent.getActivity(activity, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);


    //builder.setActionButton(largeIcon, activity.getResources().getString(R.string.custom_tag_share_description), pendingIntent ,true);
    builder.setActionButton(largeIcon, activity.getResources().getString(R.string.custom_tag_share_description), pendingIntent);

    CustomTabsIntent customTabsIntent = builder.build();
    customTabsIntent.launchUrl(activity, Uri.parse(webUrl));

}

How do I get the action button inside the toolbar close to the three dots? Am I missing something?


Solution

  • Problem was that Chrome Custom Tabs only accepts 24/48 dp bitmaps, mine was higher. Just after changing the resource file by another with the accepted resolution, it worked fine.