大型通知图标背景 [英] Large notification icon background

查看:577
本文介绍了大型通知图标背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Android 5.0大图标在通知中有背景颜色:

Since Android 5.0 large icons in notifications have color background:

有关小图标,这是通知强调色( Notification.Builder.setColor(INT))。如何设置它大图标?它是实际的图像的一部分?如果是,又该圆的半径是什么?

For small icon, it is the accent color of notification (Notification.Builder.setColor(int)). How do I set it for large icon? Is it part of the actual image? If it is, what should the circle radius be?

推荐答案

是的,大图标的颜色是实际图像的一部分。棒棒糖上的大图标的尺寸 40x40dp 用光学视图填充整个图像。所以,你应该建立40x40dp的资产与20dp半径的圆。 您可以设置通知的大图标如下:

Yes, the color of the large icon is part of the actual image. The dimensions of the large icon on lollipop are 40x40dp with a optical view filling the entire image. So you should create an asset of 40x40dp with a circle of a 20dp radius. You can set the notification's large icon as follows:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
    .setSmallIcon(R.drawable.notification_small_icon)
    .setLargeIcon(notificationLargeIconBitmap)
    .setContentTitle("Notification")
    .setContentText("Content text")
    .setColor(context.getResources().getColor(R.color.accent_color));

如果你需要的大图标是从绘制资源,你可以得到一个位图实例是这样的:

If you need the large icon to be from a drawable resource you can get a Bitmap instance like this:

Bitmap notificationLargeIconBitmap = BitmapFactory.decodeResource(
    context.getResources(), 
    R.drawable.notification_large_icon);

如果您希望您的通知被很好地与Android的previous版本显示(奇巧及以下),你应该有你的大图标的平方版本的尺寸 64x64dp

If you want your notification to be displayed nicely with previous versions of android (kitkat and below), you should have a squared version of your large icon with a dimension of 64x64dp.

这篇关于大型通知图标背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆