Recently, my users send me the following screenshot, when Android 9.0 Pie & Android OS's Night Mode is enabled.
As you can see, the stock name is not visible, because black color is applied for stock name. In normal white theme, it supposes to look as following
This is my code use to highlight the text color. In my code, I always assume the background for drop down notification is white. (Which is not correct in case dark mode is enabled)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="NotificationTitle" parent="android:TextAppearance.Material.Notification.Title"></style>
</resources>
public SpannableString getFallBelowSpannableString(Context context) {
if (fallBelowSpannableString != null) {
return fallBelowSpannableString;
}
if (fallBelow == null) {
return null;
}
// The attributes you want retrieved
int[] attrs = {android.R.attr.textColor};
TypedArray ta = context.obtainStyledAttributes(R.style.NotificationTitle, attrs);
int textColor;
try {
textColor = ta.getColor(0, context.getResources().getColor(R.color.notification_symbol_name));
} finally {
ta.recycle();
}
final String notificationMessage = context.getString(R.string.falls_below_template, symbol, org.yccheok.jstock.watchlist.Utils.toStockPrice(fallBelow));
fallBelowSpannableString = new SpannableString(notificationMessage);
ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(textColor);
fallBelowSpannableString.setSpan(foregroundColorSpan, 0, symbol.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return fallBelowSpannableString;
}
May I know, how to get the notification drop-down background color, and decide best text color when night Mode is enabled?