[UNMAINTAINED] android 5.0 lollipop 风格 Heads-up
下面介绍一个自己写的,类似 Heads-up 组件的库. github 源码地址 simple heads-up (no expand) 使用方法: ~~~ HeadsUpManager manage = HeadsUpManager.getInstant(getApplication()); HeadsUp.Builder builder = new HeadsUp.Builder(MainActivity.this); builder.setContentTitle("提醒").setDefaults(Notification.DEFAULTSOUND | Notification.DEFAULTLIGHTS) //要显示通知栏通知,这个一定要设置 .setSmallIcon(R.drawable.icon) //2.3 一定要设置这个参数,否则会报错 .setContentIntent(pendingIntent) .setContentText("你有新的消息");
HeadsUp headsUp = builder.buildHeadUp(); manage.notify(code++, headsUp);
simple heads-up 使用方法:
HeadsUpManager manage = HeadsUpManager.getInstant(getApplication()); HeadsUp.Builder builder = new HeadsUp.Builder(MainActivity.this); builder.setContentTitle("提醒").setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS) //要显示通知栏通知,这个一定要设置 .setSmallIcon(R.drawable.icon) .setContentText("你有新的消息") //2.3 一定要设置这个参数,否则会报错 .setContentIntent(pendingIntent) //设置是否显示 action 按键 .setUsesChronometer(true) .addAction(R.drawable.ic_cloud_queue_black_24dp, "查看", pendingIntent);HeadsUp headsUp = builder.buildHeadUp(); manage.notify(code++, headsUp);
使用自定义布局,支持 button 的点击事件. 使用方法:
final HeadsUpManager manage1 = HeadsUpManager.getInstant(getApplication());
View view=getLayoutInflater().inflate(R.layout.custom_notification, null);view.findViewById(R.id.openSource).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/zzz40500/HeadsUp")); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); MainActivity.this.startActivity(intent); manage1.cancel(); } }); HeadsUp headsUp1 = new HeadsUp.Builder(MainActivity.this) .setContentTitle("标题") //要显示通知栏通知,这个一定要设置 .setSmallIcon(R.drawable.icon) //2.3 一定要设置这个参数,否则会报错 .setContentIntent(pendingIntent) .setContentText("这个是自定义通知") .buildHeadUp(); headsUp1.setCustomView(view); manage1.notify(code++, headsUp1);
![]()
局限性: >1.
heads-up 没有加入阴影效果:
1.0.1更新内容; >增加了背景阴影部分.
1.1.0更新内容; >* 增加了圆形头像,基于CircleImageView上做的修改
setActivateStatusBar(boolean )
默认 true ,设置 false 表示只显示 heads-up ,而不会发送到通知栏上.#####1.1.0注意:#####
>*使用原生的 headsUp 逻辑是:
系统是大于21,且headsUp 没有使用setCustomView(View )
也没有设置setIsActivateStatusBar(true)
则使用原生的 heads-up
如果要调用了原生的 heads-up,所以你得设置setFullScreenIntent(pendding,false)
pendding不能为空,否则没有效果