У меня проблема с изменением фона фона с помощью приложения-темы.Изменение уведомлений RemoteViews Цвет фона
NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this);
TypedValue typedValue = new TypedValue();
getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true);
int iPrimaryColor = typedValue.data;
getTheme().resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);
int iPrimaryDarkColor = typedValue.data;
Intent notIntent = new Intent(getApplicationContext(), MainActivity.class);
notIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent notOpenOnClick = PendingIntent.getActivity(getApplicationContext(), 0, notIntent, PendingIntent.FLAG_UPDATE_CURRENT);
RemoteViews smallContentView = new RemoteViews(getPackageName(), R.layout.notification_small);
RemoteViews bigContentView = new RemoteViews(getPackageName(), R.layout.notification_expanded);
nBuilder.setSmallIcon(R.drawable.not_icon)
.setOngoing(true)
.setContentTitle(getCurrentSong().getTitle())
.setContentIntent(notOpenOnClick);
Notification not = nBuilder.build();
smallContentView.setInt(R.id.not_linLayout, "setBackgroundColor", iPrimaryColor);
smallContentView.setInt(R.id.not_imvDivider, "setBackgroundColor", iPrimaryDarkColor);
bigContentView.setInt(R.id.not_linLayout, "setBackgroundColor", iPrimaryColor);
bigContentView.setInt(R.id.not_imvDivider, "setBackgroundColor", iPrimaryDarkColor);
setListeners(smallContentView);
setListeners(bigContentView);
not.contentView = smallContentView;
not.bigContentView = bigContentView;
if (isPlaying()) {
not.contentView.setImageViewResource(R.id.not_btnPlayPause, R.drawable.ic_pause_48dp);
not.bigContentView.setImageViewResource(R.id.not_btnPlayPause, R.drawable.ic_pause_48dp);
}
else {
not.contentView.setImageViewResource(R.id.not_btnPlayPause, R.drawable.ic_play_48dp);
not.bigContentView.setImageViewResource(R.id.not_btnPlayPause, R.drawable.ic_play_48dp);
}
Я уже пробовал это, но фон моего уведомления по-прежнему остается белым. Идентификаторы верны, представление linLayout представляет собой LinearLayout.
Обратите внимание: целые коды вызывают в Сервисе!
Спасибо!
Похоже, вы пытаетесь создать уведомление о средствах массовой информации. Пожалуйста, не используйте специальное уведомление для этого, но вместо этого используйте [NotificationCompat.MediaStyle] (https://developer.android.com/reference/android/support/v7/app/NotificationCompat.MediaStyle.html) – ianhanniballake
Хорошо, но почему лучше ли использовать MediaStyle? –
1) Работает на устройствах API 7+ 2) Использует встроенный стиль на Lollipop + 3) Автоматически адаптируется к новому стилю уведомления Android N 4) Встроена поддержка пользовательского цвета фона 5) Создала поддержку для работы вокруг проблем с увольнением уведомлений из служб переднего плана на устройствах, предшествующих Lollipop. 6) Поддерживает добавление маркера MediaSession для управления работой Android Wear. Назвать несколько. – ianhanniballake