我使用的是Nexus 5 (SDK 4.4.4),我试图发送一些不同颜色的通知。我试着用一个简单的代码来测试颜色:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NotificationManager notif = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
for (int i = 0; i < 8; i++) {
notif.cancel(1); // clear previous notification
final Notification notification = new Notification();
if (i == 0){
notification.ledARGB = Color.MAGENTA;
}else if (i == 1){
notification.ledARGB = Color.BLUE;
}else if (i == 2){
notification.ledARGB = Color.CYAN;
}else if (i == 3){
notification.ledARGB = Color.GRAY;
}else if (i == 4){
notification.ledARGB = Color.GREEN;
}else if (i == 5){
notification.ledARGB = Color.RED;
}else if (i == 6){
notification.ledARGB = Color.WHITE;
}else if (i == 7){
notification.ledARGB = Color.YELLOW;
}
notification.ledOnMS = 1000;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notif.notify(1, notification);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
这段代码应该发送8种不同的颜色通知。我的手机实际上是复制3种颜色,蓝色,红色和洋红色。其余的颜色似乎不起作用。
当然,其他颜色实际上应该可以工作,因为光流应用程序成功地发送了带有绿色等颜色的通知。
这里有什么问题吗?是否有另一种代码可以实际工作?
发布于 2014-09-20 09:42:07
我再次尝试编译这个程序,我想出了解决方案。
对于其他有同样问题的人,在我多次运行程序之后,颜色开始显示,在重新启动我的手机后,这个程序现在运行得很好。
发布于 2014-07-31 12:55:23
您可以阅读以下内容:https://developer.android.com/preview/notifications.html,如果您在那里查看,可以看到Google不建议更改通知的颜色,他们建议使用透明的颜色,我引用如下:
“不要
使用颜色来区分应用程序和其他应用程序。通知图标只应是白色的透明背景图像.“
-编辑--我错了,我没见过你想改变led颜色,
但如果您只想更改所显示的颜色,请尝试使用代码(如:notification.ledARGB = 0xFFff0000;
)来表示所需的颜色。
https://stackoverflow.com/questions/25059025
复制相似问题