4

I am using Chrome Custom Tabs to display web content in my app. Obviously one of the main advantages of this is the ability to change UI colours in the tab. However, I need to change the status bar colour to something other than a darker version of the primary colour I provide.

Is there anyway to do this?

For reference, here is my code as it stands.

CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor(getResources().getColor(R.color.colorPrimary));
builder.setSecondaryToolbarColor(getResources().getColor(R.color.colorPrimary));
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(MainActivity.this, Uri.parse(url));

As you can probably guess, I want to change the status bar colour to R.color.colorPrimary rather than the automatically selected colour.

Any help is greatly appreciated

1 Answers1

2

As for now, you cannot change the status bar color when using Custom Tabs. You can check it by yourself from the source code of CustomTabsIntent.Builder to see what you can customize or see the documentation.

I don't try it by myself yet, but if you are targeting api >= 21 (Lollipop), I think the following code could be a work around.

@Override
public void onStart() {
    super.onStart();
    setStatusBarColor(R.color.colorPrimaryDark);
}

private void setStatusBarColor(int colorId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(ContextCompat.getColor(this, colorId));
}

private void showUrl(String url) {
    setStatusBarColor(R.color.colorPrimary);
    yourCustomTabsIntent.launchUrl(this, Uri.parse(url));
}
marcelljee
  • 336
  • 2
  • 9