[英]Android Wear - use specified solid color for notification background
出于某种原因,我无法让这个简单的概念适用于Android的佩戴。 我希望Wear上的通知具有纯色背景和我选择的颜色。 这就是我想要做的:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder
.setContentTitle("title")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentText("Text")
.setColor(Color.YELLOW);
Notification notification = builder.build();
notificationManager.notify(123456, notification);
如您所见,我将通知颜色设置为黄色。 这确实将通知背景设置为手机上的黄色。 但出于某种原因,我在Android Wear上看到的通知的背景颜色是绿色的。 请参阅随附的屏幕截图。
我尝试使用WearableExtender扩展通知构建器,但它没有类似“setColor”的方法,只有“setBackground”。 为什么Wear会忽略指定的通知颜色? 它从哪里采取绿色背景颜色? 如何覆盖该颜色?
从您的象颜色的绿色背景。
您可以调用WearableExtender setBackground方法
int notificationId = 001;
Bitmap bitmap = Bitmap.createBitmap(320,320, Bitmap.Config.ARGB_8888);
bitmap.eraseColor(Color.YELLOW);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle("title")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentText("Text")
.extend(new NotificationCompat.WearableExtender().setBackground(bitmap));
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
notificationManagerCompat.notify(notificationId , builder.build());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.