I've been trying to explore the Google Chrome custom tabs tool but something is intriguing me.
Using the following version of the library on Android Studio
compile 'com.android.support:customtabs:23.2.0'
and then running a sample using the CustomTabsIntent
isn't working as I expected.
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder(customTabActivityHelper.getSession())
.setCloseButtonIcon(BitmapFactory.decodeResource(getContext().getResources(), R.drawable.ic_action_back))
.setToolbarColor(Color.RED)
.addDefaultShareMenuItem()
.build();
CustomTabActivityHelper.openCustomTab(getActivity(), customTabsIntent, Uri.parse(url), null);
Using this, only the setToolbarColor()
is working. The setCloseButtonIcon()
, addDefaultShareMenuItem()
or even other instructions are not taking any effect.
Has anybody experienced something like this?
There are two different reason:
setCloseButtonIcon
probably doesn't work because the bitmap you use has the wrong dimensions. As documented by developer.android.com:
Key that specifies the Bitmap to be used as the image source for the action button. The icon should't be more than 24dp in height (No padding needed. The button itself will be 48dp in height) and have a width/height ratio of less than 2.
You can get the correct back arrow bitmap from the custom-tabs-client repo.
addDefaultShareMenuItem
As you can see on chromium.org the default share button is a newly added feature and it currently works only with Chrome Beta and Chrome Dev. You need to wait that Chrome Stable will be updated with this feature, in the meantime this parameter will be ignored on the stable version.