簡體   English   中英

當背景顏色為白色時,不會更改Android通知圖標顏色

[英]Android notification icon color is not changed when background color is white

我升級了android 6.0,我的應用程序有問題。

當狀態欄背景顏色不是白色時,通知圖標是好的。 (通知圖標png只有白色和alpha)

但如果某些應用將背景顏色更改為白色,則我的通知圖標不會反轉為黑色。

當狀態欄背景顏色由其他應用設置為白色時,如何將白色通知圖標反轉為黑色? (我不是說如何使用彩色圖標。)

下圖顯示了一個問題。

正常狀態

將背景顏色更改為白色時,我的圖標不會更改為黑色

  • 通知構建代碼

     Notification.Builder mBuilder = new Notification.Builder(context) .setSmallIcon(R.drawable.ic_notifications_none) .setPriority(priority2) .setOngoing(true); mBuilder.setContent(generateMessageView(message)); Intent notificationIntent = new Intent(context, MainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mBuilder.setContentIntent(intent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); 
  • 值-V23 / styles.xml

     <style name="AppTheme" parent="android:Theme.Material.NoActionBar"> </style> 

**找到解決方案**

我在drawable目錄中添加了通知圖標而不是drawable- * dpi。 現在它正在運作。

回答已經很晚了,但對於那些有同樣問題的人來說,

我也有這個問題,我發現問題出在圖形圖標上。 您可以使用此在線工具解決問題。 打開這個鏈接:

https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.type=image&source.space.trim=1&source.space.pad=0&name=ic_stat_call_white

選擇您的圖像(具有大尺寸),下載資源並將其復制到您的項目中。

最后使用.setSmallIcon(R.drawable.ICON_NEW_NAME)設置通知圖標

希望這可以幫助

我認為問題出在設備android 5.0或高。

https://developer.android.com/design/patterns/notifications.html
https://developer.android.com/about/versions/android-5.0-changes.html

這是一個解決方案:

Notification notification = new Notification.Builder(context)
        .setAutoCancel(true)
        .setContentTitle("My notification")
        .setContentText("Look, white in Lollipop, else color!")
        .setSmallIcon(getNotificationIcon())
        .build();

return notification;

和方法getNotificationIcon()

private int getNotificationIcon() {
    boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
    return useWhiteIcon ? R.drawable.icon_black : R.drawable.ic_nomarl;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM