简体   繁体   中英

Chrome custom tabs - setCloseButtonIcon() not changing icon

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

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>

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())
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM