4

I'm trying to change icon for close button in Chrome custom tabs. But it is not changing.

Here's my code:

CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setCloseButtonIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_arrow_back));
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(url));
RandomyzeEverything
  • 764
  • 3
  • 7
  • 21

2 Answers2

2

Old question, but I stumbled across this and recently had what I believe is the same problem, so I'll answer.

I believe the issue is that you are using a vector drawable, but your code expects a PNG. I ran into this issue when I used a debugging breakpoint to discover that the result of parsing the image file was null.

This answer helped me. Here's the most relevant code section from that answer. It uses Android KTX.

AppCompatResources.getDrawable(activity, R.drawable.ic_arrow_back_white_24dp)?.let {
    builder.setCloseButtonIcon(it.toBitmap())
}
Chad Schultz
  • 7,770
  • 6
  • 57
  • 96
1

According to this documentation, the close icon needs to be 24dp x 24dp. Something like this works:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24"
    android:tint="?attr/colorControlNormal">
  <path
      android:fillColor="@android:color/white"
      android:pathData="M7.2,14.4m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0"/>
  <path
      android:fillColor="@android:color/white"
      android:pathData="M14.8,18m-2,0a2,2 0,1 1,4 0a2,2 0,1 1,-4 0"/>
  <path
      android:fillColor="@android:color/white"
      android:pathData="M15.2,8.8m-4.8,0a4.8,4.8 0,1 1,9.6 0a4.8,4.8 0,1 1,-9.6 0"/>
</vector>
Code on the Rocks
  • 11,488
  • 3
  • 53
  • 61