【问题标题】:Android notification icon to change background according to status bar colorAndroid通知图标根据状态栏颜色改变背景
【发布时间】:2018-06-22 07:10:43
【问题描述】:

我正在制作一个应用程序,它会在完成特定任务时显示通知。这是我的代码:

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

这是我的图标(来自https://material.io/icons/#ic_signal_cellular_4_bar):

运行时,图标显示正常,但不会根据状态栏的背景改变颜色,例如 whatsapp 的图标会:

所以我的问题是如何让它根据背景改变颜色。

编辑:

此外,当使用白色图标时,它不会改变颜色。

【问题讨论】:

    标签: java android notifications


    【解决方案1】:

    引用the documentation:

    状态栏图标仅由透明背景上的白色像素组成,并在适当的情况下使用 alpha 混合来平滑边缘和内部纹理。

    您的图标似乎使用黑色像素。尝试下载那个图标的白色版本,看看你是否有更好的运气。

    【讨论】:

    • 我试过了,可惜没用,现在图标一直是白色的。
    • @ConnerDassen:尝试使用 Android Studio 中的图像资产向导,设置为“通知图标”,然后从剪贴画中选择 4 格蜂窝信号图标。
    猜你喜欢
    • 1970-01-01
    • 2015-09-26
    • 1970-01-01
    • 2019-11-20
    • 2016-10-16
    • 2012-02-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多