android-setCloseButtonIcon(位图可绘制)不适用于ChromeCustomTab中的SVG

android-setCloseButtonIcon(位图可绘制)不适用于ChromeCustomTab中的SVG,第1张

概述我需要在ChromeCustomTabAndroid中更改默认的跨图标,请使用以下代码使用后图标进行更改:Bitmapicon=BitmapFactory.decodeResource(context.getResources(),R.drawable.ic_arrow_back_white_24dp);它与PNG兼容,但与SVG兼容.根据本文档,我们必须根据本文档维护图像的大小.h

我需要在ChromeCustomTab Android中更改默认的跨图标,请使用以下代码使用后图标进行更改:

Bitmap icon = BitmapFactory.decodeResource(context.getResources(),R.drawable.ic_arrow_back_white_24dp);

它与PNG兼容,但与SVG兼容.

根据本文档,我们必须根据本文档维护图像的大小.

https://developer.android.com/reference/android/support/customtabs/CustomTabsIntent.html#KEY_ICON

我认为这是行不通的,因为他们没有遵循文档中给出的尺寸.

解决方法:

您需要返回一个有效的位图.对于VectorDrawable,有必要做更多的事情.您可以使用以下方法:

private static Bitmap bitmapFromDrawable(Context context, int drawableID) {    Drawable drawable = ContextCompat.getDrawable(context, drawableID);    if (drawable instanceof VectorDrawable) {        return bitmapFromVectorDrawable((VectorDrawable) drawable);    }    return ((BitmapDrawable) drawable).getBitmap();}@TargetAPI(Build.VERSION_CODES.LolliPOP)private static Bitmap bitmapFromVectorDrawable(VectorDrawable vectorDrawable) {    Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWIDth(), vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);    Canvas canvas = new Canvas(bitmap);    vectorDrawable.setBounds(0, 0, canvas.getWIDth(), canvas.getHeight());    vectorDrawable.draw(canvas);    return bitmap;}

然后您可以像这样使用它:

builder.setClosebuttonIcon(bitmapFromDrawable(this, R.drawable. ic_arrow_back_white_24dp));
总结

以上是内存溢出为你收集整理的android-setCloseButtonIcon(位图可绘制)不适用于ChromeCustomTab中的SVG全部内容,希望文章能够帮你解决android-setCloseButtonIcon(位图可绘制)不适用于ChromeCustomTab中的SVG所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1093721.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存