簡體   English   中英

棉花糖中的通知圖標變為白色

[英]Notification icon turns white in Marshmallow

我正在嘗試使用具有透明背景的彩色圖像作為通知圖標。 這在較舊的android版本中工作正常,但是當我在棉花糖(6.0)上對其進行測試時,它變成白色。 我試圖在Google上找到解決方案,並嘗試了但沒有成功。 這是我的代碼:

NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context,Activity_Notification.class);
notificationIntent.putExtra("MSG", message);
if (notificationIntent != null){
int number = createRandomInteger();
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent;
intent = PendingIntent.getActivity(context, number,
notificationIntent, Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(number, notification);
}

請幫助我擺脫這個問題。

檢查此鏈接 ,上方的棒棒糖通知圖標只能是白色或透明

根據Android 5.0的行為更改

系統將忽略操作圖標和主通知圖標中的所有非Alpha通道。 您應該假定這些圖標將僅是Alpha。 系統以白色繪制通知圖標,以深灰色繪制動作圖標。

您可以使用setColor()更改在通知中可見的背景顏色,但是小圖標將始終僅是純alpha樣式的,即由系統上色。

暫無
暫無

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

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