zoukankan      html  css  js  c++  java
  • notification

    3种notification:

    1. Dialog 循环进度条:适合前端activity。

    2. Toast: 不需要用户干预, service也可。

    默认: Toast.makeText(context, text, duration).show();
    设置显示位置:toast.setGravity(Gravity.CENTER_VERTICAL,0,0);
    自定义view:toast.setView(layout);

    3. Status notification: 适合service引起用户注意。

    Status notification较复杂,如下:

    1、获得service:nm = getSystemService(Context.NOTIFICATION_SERVICE);

    2、定义PendingIntent:PendingIntent.getActivity(this, 0, new Intent(this, MyClass.class), 0);

    3、定义notification:new Notification(icon, text, when).setLatestEventInfo(context, tiltel, text, pendingIntent);

      notification包括(具体见源代码):

        icon:显示在状态栏;

        可选的ticker-text:显示在状态栏的简单消息;

        下拉中的通知内容:默认是title、message;可自定义layout,使用满足RemoteView的控件,notification.contentIntent = pendingIntent

        PendingIntent:用户选中通知后发送该intent给Android处理;

        可选的sound、震动、led;

        可选的flag:FLAG_AUTO_CANCEL用户点击后自动消失;FLAG_INSISTENT重复sound;FLAG_ONGOING_EVENT;FLAG_NO_CLEAR不可清除;number通知的事件个数;iconLevel同LevelListDrawable在状态栏显示不同icon;

    4、发通知:nm.notify(ID, notification);

      ID,标识不同通知,cancel(id)主动销毁。

    5、更新通知:setLatestEventInfo(),notify(ID,not);

  • 相关阅读:
    常见网络设备工作原理
    Linux逻辑卷的创建
    关于华为模拟器eNSP-防火墙USG6000V怎么重装镜像
    一人之下(名言吧)
    Struts2学习笔记——Struts2搭建和第一个小程序
    eclipse部署Tomcat9
    通过反射访问类的私有方法(无参)
    Java学习笔记之——IO
    Java学习笔记之——线程的生命周期、线程同步
    Java学习笔记之——多线程
  • 原文地址:https://www.cnblogs.com/toven/p/2659069.html
Copyright © 2011-2022 走看看