setCloseButtonIcon() method doesn't change default Close button

后端 未结 2 1013
小蘑菇
小蘑菇 2021-01-01 19:03

I try to change default icon for Close Button in Chrome custom tabs (CustomTabsIntent.Builder)

Simple code for testing:

Bitmap closeIcon = BitmapFact         


        
相关标签:
2条回答
  • 2021-01-01 19:18

    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

    0 讨论(0)
  • 2021-01-01 19:28

    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.

    0 讨论(0)
提交回复
热议问题