Skip to content Skip to sidebar Skip to footer

SetCloseButtonIcon() Method Doesn't Change Default Close Button

I try to change default icon for Close Button in Chrome custom tabs (CustomTabsIntent.Builder) Simple code for testing: Bitmap closeIcon = BitmapFactory.decodeResource(getResources

Solution 1:

Typically this is caused by using a bitmap that has the 'wrong' dimensions. The correct dimensions are documented here: https://developer.android.com/reference/android/support/customtabs/CustomTabsIntent.html#KEY_ICON


Solution 2:

The close icon needs to be 24dp x 24dp. Something like this:

<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>

In Kotlin, you can retrieve this drawable and add it to your builder like this:

AppCompatResources.getDrawable(main, R.drawable.close_icon)?.let {
            DrawableCompat.setTint(it, Color.WHITE)
            builder.setCloseButtonIcon(it.toBitmap())
        }

This answer has some more details.


Post a Comment for "SetCloseButtonIcon() Method Doesn't Change Default Close Button"