setCloseButtonIcon()方法不会更改默认的“关闭"按钮 [英] setCloseButtonIcon() method doesn't change default Close button
本文介绍了setCloseButtonIcon()方法不会更改默认的“关闭"按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试在Chrome自定义标签(CustomTabsIntent.Builder)中更改关闭按钮"的默认图标
I try to change default icon for Close Button in Chrome custom tabs (CustomTabsIntent.Builder)
简单的测试代码:
Bitmap closeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
intentBuilder.setCloseButtonIcon(closeIcon);
但是什么也没发生.为什么?(Nexus 7,棉花糖)
But nothing happens. Why? (Nexus 7, Marshmallow)
推荐答案
关闭图标必须为24dp x 24dp.像这样:
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>
在Kotlin中,您可以检索此可绘制对象并将其添加到构建器中,如下所示:
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())
}
此答案还有更多详细信息.
这篇关于setCloseButtonIcon()方法不会更改默认的“关闭"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文