Reputation: 1
I want to define the Notification UI,because in some phones the notification background color is white, and in other phones is dark. I want to check what is the background color so to choose a different layout.
Before android N, my code was like this class:
The principle is to check the default contentView
title and content TextView
color. But after android N the default contentView
is null
.
Notification#build:
public Notification build() {
if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N
&& (useExistingRemoteView())) {
if (mN.contentView == null) {
mN.contentView = createContentView();
mN.extras.putInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT,
mN.contentView.getSequenceNumber());
}
if (mN.bigContentView == null) {
mN.bigContentView = createBigContentView();
if (mN.bigContentView != null) {
mN.extras.putInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT,
mN.bigContentView.getSequenceNumber());
}
}
if (mN.headsUpContentView == null) {
mN.headsUpContentView = createHeadsUpContentView();
if (mN.headsUpContentView != null) {
mN.extras.putInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT,
mN.headsUpContentView.getSequenceNumber());
}
}
}
if ((mN.defaults & DEFAULT_LIGHTS) != 0) {
mN.flags |= FLAG_SHOW_LIGHTS;
}
return mN;
}
So my question is: How to check whether the notification background color is dark or white after Android N?
Upvotes: 0
Views: 916
Reputation: 200080
It is not recommended to set custom colors on the text of your notification. Instead, you should use the TextAppearance.Compat.Notification styles for your text:
TextAppearance.Compat.Notification
for regular text in your notificationTextAppearance.Compat.Notification.Title
for the title styleTextAppearance.Compat.Notification.Info
(or Line2
) for secondary textThese styles automatically have the correct colors already built in.
For media apps, as such is the one you mention, Notifications should be built with NotificationCompat.MediaStyle
, which also takes into account the correct background and text colors.
Upvotes: 0