有没有办法让Android中的通知背景透明化?我正在使用带有Layout和NotificationCompat的RemoteViews创建通知:
RemoteViews rv = new RemoteViews(getPackageName(), R.layout.notification_layout);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContent(rv);
布局的背景LinearLayout设置为透明。但在Lollipop中,背景始终显示为白色。
答案 0 :(得分:4)
不幸的是,没有办法。
白色是通知行的背景,而不是通知本身。您的透明RemoteViews
会在通知行的顶部绘制。
技术细节:
通知的外观在SystemUI package中定义。白色在colors.xml中定义,用于ActivatableNotificationView.java。
根据源代码,唯一可以覆盖此颜色的地方是setTintColor method,但只能从BaseStatusBar.java and only for media notifications调用。
然而,即使对于媒体通知,透明色也不起作用,可能是因为setAlpha(1)
。