android通知背景色,android – 更改通知RemoteViews背景颜色
我在使用Application-Theme更改Background-Color时遇到问题.
NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this);
TypedValue typedValue = new TypedValue();
getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true);
int iPrimaryColor = typedValue.data;
getTheme().resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);
int iPrimaryDarkColor = typedValue.data;
Intent notIntent = new Intent(getApplicationContext(), MainActivity.class);
notIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent notOpenOnClick = PendingIntent.getActivity(getApplicationContext(), 0, notIntent, PendingIntent.FLAG_UPDATE_CURRENT);
RemoteViews smallContentView = new RemoteViews(getPackageName(), R.layout.notification_small);
RemoteViews bigContentView = new RemoteViews(getPackageName(), R.layout.notification_expanded);
nBuilder.setSmallIcon(R.drawable.not_icon)
.setOngoing(true)
.setContentTitle(getCurrentSong().getTitle())
.setContentIntent(notOpenOnClick);
Notification not = nBuilder.build();
smallContentView.setInt(R.id.not_linLayout, "setBackgroundColor", iPrimaryColor);
smallContentView.setInt(R.id.not_imvDivider, "setBackgroundColor", iPrimaryDarkColor);
bigContentView.setInt(R.id.not_linLayout, "setBackgroundColor", iPrimaryColor);
bigContentView.setInt(R.id.not_imvDivider, "setBackgroundColor", iPrimaryDarkColor);
setListeners(smallContentView);
setListeners(bigContentView);
not.contentView = smallContentView;
not.bigContentView = bigContentView;
if (isPlaying()) {
not.contentView.setImageViewResource(R.id.not_btnPlayPause, R.drawable.ic_pause_48dp);
not.bigContentView.setImageViewResource(R.id.not_btnPlayPause, R.drawable.ic_pause_48dp);
}
else {
not.contentView.setImageViewResource(R.id.not_btnPlayPause, R.drawable.ic_play_48dp);
not.bigContentView.setImageViewResource(R.id.not_btnPlayPause, R.drawable.ic_play_48dp);
}
我已经尝试过了,但我的通知背景仍然是白色的.
ID是正确的,View linLayout是LinearLayout.
请记住:整个代码在服务中调用!
谢谢!
解决方法:
通过利用NotificationCompat.MediaStyle,可以更轻松地完成大部分工作.它可以在API 24之前的设备上从setColor()调用中获取背景颜色(并在API 24设备上使用该颜色作为重点).这也意味着您不再需要编写任何自定义RemoteViews代码,因为它仅依赖于您添加到媒体控件通知中的操作:
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
// 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));
标签:android,service,notifications,themes,android-remoteview
来源: https://codeday.me/bug/20191008/1874783.html
android通知背景色,android – 更改通知RemoteViews背景颜色相关推荐
- android自定义主题背景颜色,Android 自定义SeekBar 实现分段显示不同背景颜色的示例代码...
在最近的开发工作中,要实现一个调色板的进度条,SeekBar要分成10段显示不同颜色,功夫不负有心人,终于实现了这个功能,下面分享给大家 示例图: 1.自定义SeekBar import androi ...
- 如何更改Code::Blocks背景颜色(懒人版)
@Code::Blocks 更改Code::Blocks背景颜色 ##经常敲代码的同学都知道Code::Blocks(以下均简称CB)的强大,但它自带的背景色让我们长时间盯着屏幕的眼睛会很不舒服: 当 ...
- Android 更改menu的背景颜色和字体颜色
在学习过程中遇到这种情况,我们想要的是白色背景,黑色字体.尝试过改背景颜色,然后再改字体颜色.当把背景颜色改为白色之后,就完全看不见.改背景颜色需要在style.xml中新增一个style. < ...
- android linearlayout背景色,Android LinearLayout 点击背景颜色改变
为了更好地用户体验, 当用户点击的时候, 要给用户feedback, 在一个布局中, 点击的时候背景颜色改变, 但我们有时候又没有专门的设计人员,这时候就自己了.如下图: 点击的时候颜色会改变 布局的 ...
- Android的自定义键盘颜色,如何在自定义键盘Android中动态更改键的背景颜色或主题...
我正在使用自定义键盘应用程序我需要设置或更改键盘的背景主题或颜色.在我的应用程序中,我们可以选择不同的背景主题和不同颜色的键行. 在第一次启动应用程序时它工作正常,但下次自定义键盘显示主题时不会更改. ...
- android linearlayout背景色,Android LinearLayout选择器背景颜色
小智.. 15 我使用线性布局作为按钮,然而,我没有任何指定为可点击的东西,它似乎工作得很好.我已经为我的标准按钮设置了一个样式,我只是将该样式分配给线性布局,就像我任何其他按钮一样. linearl ...
- android 4.2修改设置菜单的背景颜色
设置中的背景主要来主题的设置, 在4.X后, android添加了新的主题: Holo 从Settings/AndroidManifest.xml中找到: Xml代码 <applicatio ...
- java button 背景色_Swing JButton不会更改onclick的背景颜色 - java
我希望单击该按钮时它永远不会更改背景颜色,默认情况下该颜色将更改为浅蓝色灰色. 这是我的代码 JButton b = new JButton(); b.setBackground(SystemColo ...
- android设置xml为背景颜色,android – 如何通过XML将textview的背景颜色设置为全息绿光?...
通过Java: TextView test = (TextView) view.findViewById(R.id.textView2); test.setBackgroundResource(con ...
最新文章
- 知乎热议:周志华弟子 旷视南京负责人跳槽高校
- ASP.NET Core MVC/WebAPi如何构建路由?
- php网站适合优化_php开发大型网站如何优化的方案详解
- page cache 与free
- 是可改写的随机存储器_关于存储器的一些基础知识整理
- 多麦克风做拾音的波束_麦克风阵列是什么 有哪些关键技术?
- 在Service中发送广播被kill掉的Activity能不能收到?
- 哈希表和红黑树的对比
- 万字图文 | 学会Java中的线程池,这一篇也许就够了!
- BOOST1.54简化编译
- 【光学】基于matlab夫琅禾费圆孔衍射【含Matlab源码 062期】
- 深度学习多种模型评估指标介绍 - 附sklearn实现
- redmi路由器是linux,拯救小米路由器硬盘数据的方法及软件下载
- 学会网页制作,web开发,你需要掌握这3个编程语言
- 散布谣言也能实现一致性?来看看Gossip协议如何活用六度分隔理论
- 【JSON】04_JSON的生成与解析
- 电脑公司特别版5.0的驱动集成方法
- C++基础学习笔记(五)——核心编程PART3
- 拼多多求变 200 天:撒钱百亿元,江湖人称拼爹爹?
- 单片机通过mqtt联网(51单片机和esp01s)