问题描述
在我的应用中,我有一个通知,该通知包含2个操作按钮(暂停和停止),我希望这些按钮具有绿色,并将它们显示为图标,因此我创建了2个矢量,并且使用了暂停和停止Vector Asset Studio中剪贴画中的图标并将它们的颜色设置为绿色,同样在我的代码中,我使用了通知构建器类的setColor()方法并将holo_green_dark的颜色传递给它。
我已经在运行android 9的手机hu9wei 2019上尝试了此通知,一切都很好,我也在运行Android 4.4的三星galaxy neo plus上也尝试过了,按钮为绿色。
问题是当我在运行android 5的设备上尝试此通知时 (使用genymotion模拟器)时,当我尝试不使用通知生成器的setcolor()时,通知操作按钮将保持白色,而通知颜色将变为绿色。
我还不得不提到我已将通知样式设置为媒体样式,运行我的应用程序的android 5设备为Samsung galaxy S6和Google Nexus 5。
notificationBuilder = new NotificationCompat.Builder(this,channelId)
.setSmallIcon(R.drawable.my_notification_icon)
.setContentTitle(getString(R.string.app_name))
.setContentIntent(mainActivityPendingIntent)
.addAction(R.drawable.pause,getString(R.string.PAUSE_BUTTON_LABEL),pausePendingIntent)
.addAction(R.drawable.stop,getString(R.string.STOP_BUTTON_LABEL),stopPendingIntent)
.setContentText("")
.setSound(null)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true);
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
{
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(),R.drawable.my_notification_icon);
notificationBuilder.setLargeIcon(largeIcon);
notificationBuilder.setStyle(new MediaStyle().setShowActionsInCompactView(0,1));
}
else
{
notificationBuilder.setStyle(new MediaStyle());
notificationBuilder.setColor(getResources().getColor(android.R.color.holo_green_dark));
}
notification = notificationBuilder.build();
notificationmanager = (notificationmanager) this.getSystemService(Context.NOTIFICATION_SERVICE);
notificationmanager.notify(PLAYING_SOUNDS_NOTIFICATION_ID,notification);
startForeground(PLAYING_SOUNDS_NOTIFICATION_ID,notification);
这是我的其中一个向量(pause.xml)的xml:
<vector
android:height="32dp" android:tint="#43B92C"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="32dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M6,19h4L10,5L6,5v14zM14,5v14h4L18,5h-4z"/>
</vector>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)