2016-11-29 91 views
5

我有一个问题设定的Android 7.x的通知小图标黄色不能使用黄色与Android牛轧糖通知的小图标

我使用notification.setColor(Color.YELLOW);同时建设的通知对象。它显示橄榄色(ish)而不是黄色。

还试图用notification.setColor(Color.argb(255,255,255,0));但没有运气,它显示了同样的橄榄(ISH)的颜色。

这是怎么看起来像Android的7.x的

Android 7.1

这是怎么看起来像Android的6.x中,这是正确的颜色

Android 6.x

两张图片都使用相同的代码库显示相同的通知,但使用的是不同的Android设备。

我使用PushWoosh发送/接收推送通知,波纹管是我用来创建通知对象确切的代码。

public class NotificationFactory extends AbsNotificationFactory { 
@Override 
public Notification onGenerateNotification(PushData pushData) { 
    PushwooshUserdata pushwooshUserdata = GsonUtil.fromJson(pushData.getExtras().getString("u"), PushwooshUserdata.class); 

    //create notification builder 
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getContext()); 
    notificationBuilder.setContentTitle("Header"); 
    notificationBuilder.setContentText("Message"); 

    //set small icon (usually app icon) 
    notificationBuilder.setSmallIcon(R.drawable.notification_icon); 
    notificationBuilder.setColor(Color.argb(255,255,255,0)); 

    //set ticket text 
    notificationBuilder.setTicker(getContentFromHtml(pushData.getTicker())); 

    //display notification now 
    notificationBuilder.setWhen(System.currentTimeMillis()); 

    //build the notification 
    final Notification notification = notificationBuilder.build(); 

    //add sound 
    addSound(notification, pushData.getSound()); 

    //add vibration 
    addVibration(notification, pushData.getVibration()); 

    //make it cancelable 
    addCancel(notification); 

    //all done! 
    return notification; 
} 

@Override 
public void onPushReceived(PushData pushData) { 
} 

@Override 
public void onPushHandle(Activity activity) { 
} 
} 
+0

这可能是有益的描述多一点点关于你如何建立你的通知 – Chisko

+0

谢谢@Chisko,我更新的问题,包括我使用的是确切的代码。 –

回答

5

Android是确保前景色和背景色之间的最小对比度。

随着黄色(#ffff35)前景和一个白色背景,对比度为仅1.07:1。

橄榄前景(#717d13)的最小对比度为4.5:1。

这是在Android源相关补丁:https://android.googlesource.com/platform/frameworks/base.git/+/4ff3b120ff8a788e3afeb266d18caf072f0b8ffb%5E%21/

我使用http://webaim.org/resources/contrastchecker/计算上述对比度。

+0

谢谢@ eric-fikus。这就是背后的原因。 –

+0

我做了一些测试,颜色与白色的对比度小于4.5:1,它总是会得到与我选择的颜色不同的颜色,通过计算新颜色的对比度,它总是高于4.5。 你救了我的一天! –

0

尽量确保在通知UI控件也是在你的应用的Activity可用,并且当用户单击该通知,你应该始终启动该活动。为此,请使用setContentIntent()方法。

,如果你已经在colors.xml定义的颜色,然后在你的NotificationBuilder增加价值为.setColor(getResources().getColor(R.color.<YOUR_COLOR>))

来源:NotificationCompat.Builder#setColor(int)

相关问题