1
我正在构建基于Google's Universal Media Player的媒体播放器应用程序。现在我面临着玩家创建通知的问题。无法更改NotificationCompat MediaStyle文本颜色
代码来创建通知:
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService);
notificationBuilder
.setStyle(new NotificationCompat.MediaStyle()
.setShowActionsInCompactView(
new int[]{playPauseButtonPosition}) // show only play/pause in compact view
.setMediaSession(mSessionToken))
.setColor(mNotificationColor)
.setSmallIcon(R.drawable.ic_notification)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setUsesChronometer(true)
.setContentIntent(createContentIntent(description))
.setContentTitle(description.getTitle())
.setContentText(description.getSubtitle())
.setLargeIcon(art);
之后我从代码去除.setColor(mNotificationColor)部。我认为它使通知的背景变成了白色。但现在背景变成这样的灰色:
所以现在我想将背景颜色设置为白色,这是很容易的部分。 setColor
可以完成这项工作,但那时我想让文字颜色变黑。无法弄清楚如何改变文字颜色。即使我提供黑色图标也不会改变播放/暂停的图标。
我加'<样式名称= “TextAppearance.AppCompat.Notification.Title.Media” 工具:倍率= “真”> <项目名称= “机器人:文字颜色”> @ color/app_primary_text '因为这是我在[源代码]中找到的样式名称(https://github.com/android/platform_frameworks_support/blob/master/v7/appcompat/res/layout/notification_template_lines_media.xml )。但没有任何反应。文字颜色仍然是白色。 – Ratul
使用工具:override =“true”的原因是:_overriding @ style/TextAppearance_AppCompat_Notification_Title_Media在com.android.support:appcompat-v7中标记为private。如果有意,使用工具:override =“true”,否则选择一个不同的名字。 私人资源不应被引用;可能并不是到处都有,甚至它们可能在没有通知的情况下消失。 要解决这个问题,请将资源复制到您自己的项目中,而不是在覆盖时使用。 – Ratul
什么是您的最小sdk和您测试过哪个设备。 – 2017-04-10 13:27:13