Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 512
Javier Sivianes Avatar asked Oct 13 '16 14:10

Javier Sivianes


People also ask

How do I close a custom tab in Chrome?

Let, you open chrome custom tab from "MainActivity" and there is a option menu item "Close" in chrome custom tab, and on "Close" menu item click you want to close chrome custom tab and to go back the "MainActivity", then you can do it by starting "MainActivity".

What is open Tabs in custom Tabs?

Custom Tabs is a browser feature, introduced by Chrome, that is now supported by most major browsers on Android. It gives apps more control over their web experience, and makes transitions between native and web content more seamless without having to resort to a WebView.


1 Answers

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.

like image 173
Javier Sivianes Avatar answered Oct 20 '22 08:10

Javier Sivianes