更改ImageButton取决于通知背景颜色

时间:2017-10-04 13:46:31

标签: android android-layout android-notifications android-view android-resources

我收到了自定义RemoteView的通知。我can更改文字颜色,取决于通知背景颜色。但我的黑色按钮在api <21时仍然不可见,当时背景也是黑色。 有没有办法解决这个问题而不改变背景?

2 个答案:

答案 0 :(得分:0)

您可以尝试使用以下代码为您的远程视图通知设置背景颜色。

NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this);
nBuilder.setSmallIcon(R.drawable.not_icon)
  .setContentTitle(getCurrentSong().getTitle())
  .setContentIntent(notOpenOnClick);
// This is what sets the background color on <N devices
// It is an accent color on N+ devices
nBuilder.setColor(getResources().getColor(R.color.colorPrimary));
// Add actions via nBuilder.addAction()
// Set the style, setShowActionsInCompactView(0) means the first
// action you've added will be shown the non-expanded view
nBuilder.setStyle(new NotificationCompat.MediaStyle()
  .setShowActionsInCompactView(0));

答案 1 :(得分:0)

经过研究,我使用api&gt; = 21的黑色图标,以及api&lt;黑色笔划的白色图标。 21。