19

Is there any way to change a title color in Chrome Custom Tabs?

I applied Chrome custom tabs to show a web page. To do, I utilized CustomTabsIntent.Builder class. However, there is no interface to change a title color.

String url = "www.google.com";
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
intentBuilder.setToolbarColor(getResources().getColor(R.color.primary));
intentBuilder.setShowTitle(true);
intentBuilder.setCloseButtonIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_arrow_back));
intentBuilder.setStartAnimations(getActivity(), R.anim.slide_in_right, R.anim.slide_out_left);
intentBuilder.setExitAnimations(getActivity(), android.R.anim.slide_in_left, android.R.anim.slide_out_right);
CustomTabActivityHelper.openCustomTab(getActivity(), intentBuilder.build(), Uri.parse(url), new WebviewFallback());

Based on the above code, Chrome Custom Tabs displays a black-colored title text. I want to change the title to a white color.

Daehee Han
  • 201
  • 2
  • 7
  • 2
    Try setting the toolbar colour to a really dark one. If the text is white then, it may be using the same contrast check that is used for the recent apps card title bars, which means you can't change it manually other than adjusting the colour of the title bar to be a bit darker. – Kane O'Riley Sep 12 '15 at 03:54

4 Answers4

10

You can't change color of tittle programmatically in Chrome Custom Tab. The only way you can follow is Material Design Specifications.

If you have primary and primaryDark color of your app with dark shade, than Custom Tabs will use dark tittle, dark close button and dark overflow menu button.

Example of dark shade colors in Material Palette

If you have primary and primaryDark color with light shade, than Chrome Custom Tabs will use light tittle etc.

Example of light shade colors in Material Palette

So, you must pay attention on number of you primary and primaryDark color.

8

It would be nice if there was a possibility to change the color of the text and statusbar. For example our app has different color settings so now there's no coherence between the app and Chrome Custom Tabs. That looks kinda bad.

Maybe there's a chance to get Chrome Custom Tabs colors for text and statusbar so that we could adjust it to our app (we have templates that user can choose).

enter image description here

ekstro
  • 461
  • 4
  • 15
  • 5
    Seems like there is an issue reported to Google about this. Would be worth starring and commenting if people want this changed. https://code.google.com/p/android/issues/detail?id=201774 – James Britton Mar 01 '16 at 14:16
0

As mentioned in one of the responses, the title text color is chosen automatically for the best contrast with the title color, there is no other way to set it.

Egor Pasko
  • 506
  • 3
  • 11
  • So is any chance to get those colors? Not "set", but "get" so that we could adjust it (dynamically) to our app, eg. we "setToolbarColor" to yellow and get that text color on toolbar will be black. – ekstro Nov 12 '15 at 10:17
0
//custom chrome tab
`implementation "androidx.browser:browser:1.0.0"` // Use this dependency only, because setToolbarColor is deprecated in the current dependency.

val builder = CustomTabsIntent.Builder()
val intent = builder.build()enter image description here           
builder.setToolbarColor(ContextCompat.getColor(this,R.color.YourChoiceColor))
intent.launchUrl(this, Uri.parse(item.url))

enter image description here

Raghib Arshi
  • 717
  • 8
  • 12