我的应用程序正在使用带有RemoteViews的自定义通知布局。
为了显示文本,布局使用以下系统样式:
android:TextAppearance.Material.Notification.Title
android:TextAppearance.Material.Notification
这可以很好地工作。
但是,不能使用TextAppearance样式来设置android:tint
的值,所以我必须硬编码颜色。
据我所知,没有特殊的系统风格来设置通知ImageButton色调。
硬编码的颜色在当前的Android 5+系统上运行良好,但一些用户安装了自定义深色主题的自定义ROM,通知看起来是错误的,即黑色背景上的黑色图标。
有没有办法获得系统通知图标/图像按钮的颜色,并从XML布局中应用它?
或许还有另一种方法可以做到这一点?
发布于 2017-10-12 21:04:25
对不起,但据我所知,定制ROM有单独的系统设计,配置,以及非官方的。
因此,在不了解其设计的情况下支持自定义ROM是不可能的。android API是用来支持官方ROM的。
希望它能有所帮助!!
发布于 2017-10-12 15:21:26
对于背景,您可以尝试这些属性...
app:backgroundTint="@color/pay"
-或
android:tint="@color/white"
发布于 2020-10-27 20:32:59
您可以从TextAppearance_Compat_Notification_Title
获取textColor
,并将其作为色调以编程方式添加到图像中,如下所示
val remoteViews = RemoteViews(service.packageName, R.layout.notification_layout)
val icon = Icon.createWithResource(context, R.drawable.icon)
val attrs = intArrayOf(android.R.attr.textColor)
with(context.obtainStyledAttributes(R.style.TextAppearance_Compat_Notification_Title, attrs)) {
val iconColor = getColor(0, Color.GRAY)
icon.setTint(iconColor)
recycle()
}
remoteViews.setImageViewIcon(R.id.ibPlayPause, icon)
https://stackoverflow.com/questions/41544474
复制相似问题