Search code examples
androidchrome-custom-tabs

Chrome Custom Tabs customisations like setToolbarColor, start and exit animations are not working


I am new to Android and trying to open link in Chrome Custom Tabs. I have created a funtion to open any links on the app in Chrome Custom Tabs:

public static void chromeCustomTab(Context context, String url)
{
    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    CustomTabsIntent customTabsIntent = builder.build();
    customTabsIntent.launchUrl(context,Uri.parse(url));
    builder.setToolbarColor(context.getResources().getColor(R.color.colorPrimaryDark));
    builder.setStartAnimations(context, R.anim.slide_in_bottom, R.anim.slide_out_top);
    builder.setExitAnimations(context, R.anim.slide_in_top, R.anim.slide_out_bottom);
}

Now the links are opening in Chrome Custom Tabs, but none of the cosutomizations are working. The ToolbarColor is not changing, the animations are not working. Also, the site title is not visible on the Chrome Custome Tab, only the base url is visible. Please help me where I am going wrong on this.


Solution

  • add the builder settings BEFORE you launch the url :)