How to show different icons for status bar and notification bar in Android?
Asked Answered
M

2

12

I'm creating android notification according to android documentation. I used large icon and small icon for Notification bar.

In this case small icon is showing on both status bar and notification bar . I want to show different icons for status bar and notification bar, how i can achieve that ?

Martyrize answered 15/7, 2014 at 10:7 Comment(0)
K
1

There are different API's for each. See below:

Notification.Builder nb = new Notification.Builder(context)
    .setContentTitle("title")
    .setContentText("content")
    .setAutoCancel(true)
    .setLargeIcon(largeIcon)
    .setSmallIcon(R.drawable.small_icon)
    .setTicker(s.getText());

http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setSmallIcon%28int%29

http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setLargeIcon%28android.graphics.Bitmap%29

OR

As an alternative, you could use a custom notification layout.

Kreegar answered 15/7, 2014 at 10:14 Comment(5)
Yes, i created notification as the same you described. But this method ".setSmallIcon(R.drawable.small_icon)" is show small icon at Notification bar AND at status bar. Is that right ? If yes, i want to use iconA.png for Status bar icon and iconB.png for small icon at Notification bar, how can i do that?Martyrize
No. If you meant icon no.5 in the link. It will be sameKreegar
so there is no way to use different icon for that ? Only small icon will show on both at status bar and notification bar ?Martyrize
Oh i forgot that, that could be the solution. Thanks you.Martyrize
And please edit your answer for "custom notification layout" so i can accept that.Martyrize
E
9

In the documentation; there are notification area and notification drawer, i think in your case status bar means the notification area. You can use the following code to create a notification by setting both small icon and large icon.

Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_icon);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.logo).setLargeIcon(bm).setContentTitle("title").setContentText("body");

Large icon is a bitmap and it is shown in notification drawer, small icon is shown in notification area but also in the notification drawer, in the bottom right corner of the large icon. It must be entirely white. If the small icon is colorful, it is shown as a white square in the notification area.

Edith answered 25/11, 2014 at 10:22 Comment(2)
how to make the small icon entirely white?Graeae
@HammadNasir simply in your android studio click new image assets then choose icon for notification and status bar then choose your image and android studio will create the right icons.Botello
K
1

There are different API's for each. See below:

Notification.Builder nb = new Notification.Builder(context)
    .setContentTitle("title")
    .setContentText("content")
    .setAutoCancel(true)
    .setLargeIcon(largeIcon)
    .setSmallIcon(R.drawable.small_icon)
    .setTicker(s.getText());

http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setSmallIcon%28int%29

http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setLargeIcon%28android.graphics.Bitmap%29

OR

As an alternative, you could use a custom notification layout.

Kreegar answered 15/7, 2014 at 10:14 Comment(5)
Yes, i created notification as the same you described. But this method ".setSmallIcon(R.drawable.small_icon)" is show small icon at Notification bar AND at status bar. Is that right ? If yes, i want to use iconA.png for Status bar icon and iconB.png for small icon at Notification bar, how can i do that?Martyrize
No. If you meant icon no.5 in the link. It will be sameKreegar
so there is no way to use different icon for that ? Only small icon will show on both at status bar and notification bar ?Martyrize
Oh i forgot that, that could be the solution. Thanks you.Martyrize
And please edit your answer for "custom notification layout" so i can accept that.Martyrize

© 2022 - 2024 — McMap. All rights reserved.