我似乎无法使通知使用默认的通知背景颜色:它在应该为白色的地方仍保持灰色。同时,通知颜色适用于kitkat。
我已经在这个问题上实施了建议
似乎对我实施的内容没有任何影响。值-v21只是好像不存在一样。自然,我的目标sdk是21。我似乎找不到原因。
通知是使用服务显示的StartForeground。我也尝试过NotificationManager.notify(),但这没什么区别。
另外,即使我仅将包装器RelativeLayout保留在xml中,通知也将变为灰色:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)
values-v21 \ styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="NotificationText" parent="android:TextAppearance.Material.Notification" />
<style name="NotificationTitle" parent="android:TextAppearance.Material.Notification.Title" />
<style name="NotificationTime" parent="android:TextAppearance.Material.Notification.Time" />
</resources>
Run Code Online (Sandbox Code Playgroud)
尽管这些样式并未在其他任何地方使用(例如在我的应用主题声明中)。它们是刚刚定义的(在值-v21和值-v9中)。
我在使用Application-Theme更改Background-Color时遇到问题.
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 …Run Code Online (Sandbox Code Playgroud)