1 通知栏可以使用自定义布局,可以在自定义布局上添加按钮,跳转到指定的activity
2 通知栏的生命周期和应用的生命周期无关,应用退出后,通知栏可以继续存在,但应用卸载后,通知栏会消失
显示通知栏:

private void createNotification() {        NotificationCompat.Builder builder = new NotificationCompat.Builder(                this);        Intent i = new Intent(this, MainActivity.class);        i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);        PendingIntent intent = PendingIntent.getActivity(this, 0, i,                PendingIntent.FLAG_UPDATE_CURRENT);        builder.setContentIntent(intent);        builder.setTicker(getResources()                .getString(R.string.custom_notification));        //通知栏未展开时显示的小图标        builder.setSmallIcon(R.drawable.ic_stat_custom);        builder.setAutoCancel(true);        Notification notification = builder.build();        notification.flags |= Notification.FLAG_ONGOING_EVENT;        // 表明在点击了通知栏中的"清除通知"后,此通知不清除,经常与FLAG_ONGOING_EVENT一起使用        notification.flags |= Notification.FLAG_NO_CLEAR;        RemoteViews contentView = new RemoteViews(getPackageName(),                R.layout.notifycation_layout);        Intent iintent = new Intent(MainActivity.this, Activity2.class);        PendingIntent stentIntent = PendingIntent.getActivity(this, 0,                iintent, PendingIntent.FLAG_UPDATE_CURRENT);        contentView.setOnClickPendingIntent(R.id.notify_set,stentIntent);        final String time = DateFormat.getTimeInstance().format(new Date())                .toString();        final String text = getResources().getString(R.string.collapsed, time);        contentView.setTextViewText(R.id.textView, text);        notification.contentView = contentView;        NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);        nm.notify(5270, notification);    }

取消通知栏:

NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); nm.cancel(5270);

PS:使用android sdk自带的demo是了解android控件使用方法的效率最高的手段

源码下载:http://download.csdn.net/detail/victory08/9104485

更多相关文章

  1. 细节决定成败----Android应用程序的优化(四)
  2. Android开发之Android(安卓)Context,上下文(Activity Context, Ap
  3. Unity与Android对比学习之生命周期方法
  4. Android(安卓)进阶——Android(安卓)Studio 项目结构详细述及自
  5. Android仿微信朋友圈图片上传选择器布局
  6. Android性能优化之一:ViewStub(转)
  7. 动手学Android之四——布局初步(一)
  8. android的计算器简单布局————网格布局
  9. Android官方开发文档Training系列课程中文版:使用Fragment构建动

随机推荐

  1. Android(安卓)– Multithreading in a UI
  2. Android(安卓)调用系统播放器
  3. 解决TabLayout+viewpager 滑动切换时 布
  4. Android(安卓)监听 ListView 元素数量的
  5. android如何拿高薪
  6. Android(安卓)带密码输入界面的Dialog实
  7. Android:JPEG EXIF信息添加
  8. Android(安卓)添加新的联系人代码
  9. Android(安卓)view 转化为Bitmap并保存在
  10. Android中如何使用对话框(单选对话框和多