2016-11-29 23 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)

相關問題