Android界面编程之Notification(通知)
来源:互联网 发布:金城学院继续教育jaVa 编辑:程序博客网 时间:2024/05/16 15:39
NotificationManager的方法
示例:点击发送通知,通知栏由通知显示,点击取消,则消失
布局:
<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="send" android:text="发送通知"/> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="cancel" app:layout_constraintTop_toBottomOf="@id/button1" android:text="取消发送"/>
Java代码:
public class MainActivity extends AppCompatActivity { private static final int NOTIVICATIONID=0x123; private NotificationManager manager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); manager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); } public void send(View view){ NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setAutoCancel(true) .setTicker("中午加餐啦") .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("今天牛老板请客") .setContentText("牛老板请客吃烧烤") .setDefaults(Notification.DEFAULT_ALL); Notification notify = builder.build(); manager.notify(NOTIVICATIONID,notify); } public void cancel(View view){ manager.cancel(NOTIVICATIONID); }}
阅读全文
0 0
- Android界面编程之Notification(通知)
- Android编程之通知---Notification
- android之Notification通知
- android之Notification通知
- android之Notification通知
- android之Notification通知
- android之Notification通知
- android之Notification通知
- Android之Notification通知
- android之Notification通知
- android之Notification通知
- android之Notification通知
- Android--通知之Notification
- android--通知之Notification
- android之Notification通知
- Android--通知之Notification
- Android--通知之Notification
- Android--通知之Notification
- 封装简单的mvc框架
- 数据结构实验之排序一:一趟快排
- SICP 课后题及相关笔记 1
- 当DDD遇上微服务
- Java案例-用户注册邮箱绑定激活功能实现
- Android界面编程之Notification(通知)
- JSON 数组
- 51nod 1874 字符串排序
- MNIST分类
- Abstract
- PRD怎么写
- VMware下安装CentOs 7(上)
- ROS配置<一>:Ubuntu16.04下安装Kinetic
- HTML排版标签