我尝试在Chrome自定义选项卡(CustomTabsIntent.Builder)中更改关闭按钮的默认图标
简单的测试代码:
Bitmap closeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
intentBuilder.setCloseButtonIcon(closeIcon);但是什么也没发生。为什么?(Nexus 7,棉花糖)
发布于 2016-02-08 05:57:42
通常,这是由于使用具有“错误”尺寸的位图造成的。正确的尺寸记录在这里:https://developer.android.com/reference/android/support/customtabs/CustomTabsIntent.html#KEY_ICON
发布于 2020-06-03 09:18:50
关闭图标需要为24dp x 24dp。如下所示:
<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>在Kotlin中,您可以检索此可绘制内容并将其添加到构建器中,如下所示:
AppCompatResources.getDrawable(main, R.drawable.close_icon)?.let {
DrawableCompat.setTint(it, Color.WHITE)
builder.setCloseButtonIcon(it.toBitmap())
}这个answer有更多的细节。
https://stackoverflow.com/questions/34614584
复制相似问题