简体   繁体   中英

Android notification icon to change background according to status bar color

I am making an app, which displays a notification when a certain task is completed. This is my code:

int NOTIFICATION_ID = 4024;

NotificationCompat.Builder builder =
    new NotificationCompat.Builder(this)
    .setContentTitle("Title")
    .setContentText("Text")
    .setSmallIcon(R.drawable.ic_notification)
    .setLights(Color.GREEN, 1000, 1000)
    .setVibrate(new long[] {500, 500, 500, 500, 500})
    .setAutoCancel(true);

Intent resultIntent = new Intent(this, MainActivity.class);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0,
      resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(resultPendingIntent);

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, builder.build());

And this is my icon (from https://material.io/icons/#ic_signal_cellular_4_bar ):

https://material.io/icons/#ic_signal_cellular_4_bar

When running this the icon displays fine, but it doesn't change color according to the background of the status bar, like for example whatsapp's icon does:

我知道路 你知道路吗

So my question is how I can make it change color according to the background.

EDIT:

Also when using the white icon it doesn't change color.

Quoting the documentation :

Status bar icons are composed simply of white pixels on a transparent backdrop, with alpha blending used for smooth edges and internal texture where appropriate.

Your icon would appear to be using black pixels. Try downloading the white edition of that icon, and see if you have better luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM