2016-08-05 74 views
0

我已經使用這個代碼棒棒糖通知應用程序圖標只顯示白色圖標沒有其他顏色,如何設置setColorFilter圖標?

private void sendNotification() { 
     StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 

     StrictMode.setThreadPolicy(policy); 
     Intent intent = new Intent(this, LoginActivity.class); 
     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 
     int randomNumber = (int) System.currentTimeMillis(); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, randomNumber, intent, 
       PendingIntent.FLAG_ONE_SHOT); 

     Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     NotificationCompat.BigPictureStyle nbs = new android.support.v7.app.NotificationCompat.BigPictureStyle(); 
     nbs.setSummaryText("Big Message").bigPicture(BitmapFactory.decodeResource(getResources(),R.drawable.general_push)).setBigContentTitle("Big Title"); 
     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
       .setContentTitle("Small Title") 
       .setStyle(nbs) 
       .setContentText("Small Message") 
       .setAutoCancel(true) 
       .setSound(defaultSoundUri) 
       .setContentIntent(pendingIntent); 

     if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
      notificationBuilder.setSmallIcon(R.drawable.notif_trans); 
     }else{ 
      notificationBuilder.setSmallIcon(R.drawable.notif_logo); 
     } 
     NotificationManager notificationManager = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

     notificationManager.notify(randomNumber, notificationBuilder.build()); 
    } 

在我測試的圖標來了,但它是在白色而已,有人告訴說要加setColorFilter我不知道如何設置應用程序圖標我的棒棒糖設備,我用drawable ID直接設置smallIcon,在那裏我必須設置setColorFilter?請幫幫我。一些機構已經給這個代碼

if (entry.targetSdk >= Build.VERSION_CODES.LOLLIPOP) { 
    entry.icon.setColorFilter(mContext.getResources().getColor(android.R.color.white)); 
} else { 
    entry.icon.setColorFilter(null); 
}, 

這個是什麼entry.icon我們將如何獲取和如何設置的小圖標

+1

http://stackoverflow.com/questions/28387602/notification-bar-icon-turns-white-in-android-5-lollipop/28387744 –

+0

@RobertEstivill我用同樣的東西我有兩個圖標notif trans是透明的圖像,但只有橙色,但它只顯示白色(場景顏色) – Hanuman

+0

不是圖標顏色的問題,是一個棒棒糖的問題,你的圖標設置爲白色,如果你的應用程序的目標是deteminate sdk版本。閱讀鏈接的答案 –

回答

0

見下面鏈接:

Notification bar icon turns white in Android 5 Lollipop

你必須製作只有白色的圖標,並在android版本爲棒棒糖及以上時設置該圖標。

+0

因此,如果與不同顏色的圖標,像什麼的應用程序圖標將是綠色的,這樣,也將出現白色,不知道? – Hanuman

+0

是的。在棒棒糖及以上版本中,所有應用程序的通知圖標均爲白色。 –

+0

但我給出了不同的顏色,即使這段時間它也會變成白色,所以我怎樣才能改變這種顏色(應用程序圖標)有什麼方法 – Hanuman

相關問題