Android 4.1--大布局Notification

      转载请注明出处Android 4.1--大布局Notification 

       今天发现了一个谷歌4.1以上才有的的新型Notification,完成度也算比较高,自己记录一下

首先我们先看看区别所在:

  1,普通的Notification

     

     

  2,大布局的Notification

  

  这是android4.1以后才增加的,与普通Notification的区别主要就是其显示内容可以扩展,并且只有在所有的Notification的最上面时才会显示大布局,其他情况下显示小布局,也可以用手指将其扩展为大布局。


  

大布局也可分为三种类型:

InboxStyle收件箱风格:显示多行文字

BigTextStyle大文字风格:显示一个大的文字块

BigPictureStyle大图片风格:详情区域包含一个256dp高度的位图


 上面这些都来自于网上的文章,接下来上代码

  

public void onCreate() {
		manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
		textStyle = new BigTextStyle();
		builder = new NotificationCompat.Builder(this);
		super.onCreate();
	}
  先实例化一个NotificationManager,一个大文字风格的Notification,一个NotificationCompat。

	textStyle.setBigContentTitle(mName);
				textStyle.bigText(mSinger);
				builder.setSmallIcon(R.drawable.notif_icon)
						.setLargeIcon(result)
						.setTicker("播放")
						.setContentTitle(mName)
						.setContentIntent(intentApp())
						.setContentText(mSinger)
						.setStyle(textStyle)
						.setSound(null)//声音提示
						.setAutoCancel(true)
						.setDefaults(0)
						.setOngoing(true)//常驻不消失
						manager.notify(2, builder.build());

以上就是一个普通的 大文字风格的Notification,看下效果。



等等有点奇怪啊。。为什么展开之后会多了几个按钮,这是考虑到一些音乐App可能会这样设计,这是怎么做到的呢,其实也没有几句代码。

	.addAction(R.drawable.pre_video_button_nomal, null,
								preMuscic())
						.addAction(R.drawable.play_button, null, playMuscic())
						.addAction(R.drawable.next_video_button_nomal, null,
								nextMuscic()).build();

NotificationCompat.Builder.addAction就可以了。。

Android笔记--Notification  这篇文章讲解的更加详细。。有需要的朋友可以去看看

记录一下,不积跬步无以至千里


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值