Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
498 views
in Technique[技术] by (71.8m points)

android - Large notification icon background

Since Android 5.0 large icons in notifications have color background:

lollipop-notification

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...