我已經使用這個代碼棒棒糖通知應用程序圖標只顯示白色圖標沒有其他顏色,如何設置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我們將如何獲取和如何設置的小圖標
http://stackoverflow.com/questions/28387602/notification-bar-icon-turns-white-in-android-5-lollipop/28387744 –
@RobertEstivill我用同樣的東西我有兩個圖標notif trans是透明的圖像,但只有橙色,但它只顯示白色(場景顏色) – Hanuman
不是圖標顏色的問題,是一個棒棒糖的問題,你的圖標設置爲白色,如果你的應用程序的目標是deteminate sdk版本。閱讀鏈接的答案 –