Android -- 通知栏的使用
1. 效果图
2. 实现代码
public class firstActivity extends Activity {private Notification notification; // Notification对象private NotificationManager notificationManager; // NotificationManager对象 @Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);Button btn1 = (Button) findViewById(R.id.button1); // 获取按钮对象Button btn2 = (Button) findViewById(R.id.button2); // 获取按钮对象 String service = NOTIFICATION_SERVICE; // 获取系统服务notificationManager = (NotificationManager) getSystemService(service);notification = new Notification(); // 实例化一个Notificationnotification.icon = R.drawable.icon; // 指定图标notification.tickerText = "Notification测试 "; // 指定提示信息notification.when = System.currentTimeMillis(); // 指定显示的时间 btn1.setOnClickListener(new View.OnClickListener() { // 设置监听器 @Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent intent = new Intent(firstActivity.this,firstActivity.class);// PendingIntent 相当于intent 的包装类 --> 表示即将到来的事情PendingIntent pendingIntent = PendingIntent.getActivity(firstActivity.this, 0, intent, 0);notification.setLatestEventInfo(firstActivity.this, "我的标题","我的内容", pendingIntent);notificationManager.notify(1, notification); // 发出通知 }});btn2.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubnotificationManager.cancel(1); // 取消通知 }});} }
firstActivity
转载于:https://www.cnblogs.com/SM-t/p/4162513.html
Android -- 通知栏的使用相关推荐
- 如何解决android 通知栏不显示的问题
如何解决android 通知栏不显示的问题 参考文章: (1)如何解决android 通知栏不显示的问题 (2)https://www.cnblogs.com/haloujava/p/11376290 ...
- Android 通知栏Notification
Android 通知栏Notification 在android的应用层中,涉及到很多应用框架,例如:Service框架,Activity管理机制,Broadcast机制,对话框框架,标题栏框架,状态 ...
- Android通知栏Notification弹出横幅显示的解决方法
Android通知栏Notification弹出横幅显示的解决方法 参考文章: (1)Android通知栏Notification弹出横幅显示的解决方法 (2)https://www.cnblogs. ...
- android 通知栏进度_Android改造下载图片进度通知
android 通知栏进度 In this tutorial, we'll be using the Retrofit library in order to download an image fr ...
- android 通知栏样式_Android通知样式
android 通知栏样式 We've discussed and implemented basic Notifications in this post. In this tutorial, we ...
- Android通知栏字体大小,Android通知栏介绍与适配总结(上篇)
此文已由作者黎星授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 由于历史原因,Android在发布之初对通知栏Notification的设计相当简单,而如今面对各式各样的通知 ...
- android 通知栏背景颜色跟随app导航栏背景颜色变化而变化
原文地址为: android 通知栏背景颜色跟随app导航栏背景颜色变化而变化 通知栏(notification)背景颜色跟随app导航栏(top title)背景颜色变化而变化. 这也叫沉浸式状态栏 ...
- android 在状态栏耳机图标显示图标显示图标显示图标,Android 通知栏图标
先来一段发送普通通知的代码. NotificationManager notificationManager = (NotificationManager) getActivity().getSyst ...
- Android通知栏微技巧,8.0系统中通知栏的适配
转载请注明出处:https://blog.csdn.net/guolin_blog/article/details/79854070 本文同步发表于我的微信公众号,扫一扫文章底部的二维码或在微信搜索 ...
- Android通知栏和服务相关知识
Android通知栏与开启前后台服务执行下载任务 索引 自定义通知栏 关键点 后台下载,同时打开前台服务显示进度 关键点 自定义通知栏 关键点 在Android8之后,发送通知需要通知渠道,具体要求见 ...
最新文章
- crt证书iis 中引用 程序目录提示 System.UnauthorizedAccessException:拒绝访问
- 062_html多媒体
- java错误: 非法字符: '\ufeff' 需要class, interface或enum
- [云炬创业管理笔记]第6章制定创业行动测试4
- 【数学建模】多属性决策模型(评价与决策)
- 2019第一篇万字长文!30+家一线投资机构已出投资新策略...
- 用OpenSSL编写SSL,TLS程序
- 加载本地json文件,并利用批处理调用Chrome显示html
- Facebook 开源首个全卷积语音识别工具包 wav2letter++
- bzoj1048 [HAOI2007]分割矩阵
- autojs开发的ip地址查询工具开源代码免费分享
- css 文字不规则排版,DIV CSS解决不规则文字排版
- 微信公众号网页跳转及获取用户信息的接口设计
- 使用计算机教学的好处,谈计算机在教学中的作用
- 合工大计算机系汪教授,合肥工业大学计算机与信息学院导师介绍:洪日昌
- 30岁宝妈转行UI设计,后来怎么样了?
- Android常用的开源库收集(持续更新中)
- win10:取消电脑代理的方法
- Java技术进阶推荐书单
- linux 汇编 `.eabi_attribute',交叉编译arm-none-eabi-gcc编译汇编文件(startup_stm32f10x_hd.S)遇到的有关问题(2)...