Android Notification下拉样式

来源:互联网 发布:淘宝上店铺介绍怎么写 编辑:程序博客网 时间:2024/05/21 21:03

在android中接受通知,对通知的样式进行设置

public void notifyUser(int id, String title, String content, String tickerText) {// 获取系统的状态类通知notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);n = new Notification(R.drawable.icon, tickerText, System.currentTimeMillis());Intent intent = new Intent(context, CordovaApp.class);PendingIntent pi = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);n.contentIntent = pi;// 上下文、标题、内容、点击后出发的意图过滤器n.setLatestEventInfo(context, title, content, pi);n.defaults = Notification.DEFAULT_ALL; // 通知声音n.flags |= Notification.FLAG_SHOW_LIGHTS;n.flags |= Notification.FLAG_AUTO_CANCEL; // 点击后自动在状态栏消失n.icon = R.drawable.icon;n.when = System.currentTimeMillis();n.tickerText = tickerText;// 设置通知下来时候的样式// RemoteViews contentView=new// RemoteViews(getPackageName(),R.layout.pullnotice);// contentView.setImageViewResource(R.id.pullnoti,R.drawable.icon);// contentView.setTextViewText(R.id.text,content);// n.contentView=contentView;// 发送通知notificationManager.notify(id, n);}

n.icon = R.drawable.icon;
设置的是接收到消息的时候的图片
<pre name="code" class="java">n = new Notification(R.drawable.icon, tickerText, System.currentTimeMillis());
这里的R.drawable.icon是通知下拉时候的图标,

<span style="font-family: Arial, Helvetica, sans-serif;"></span>
<span style="font-family: Arial, Helvetica, sans-serif;"></span><pre name="code" class="java">// RemoteViews contentView=new// RemoteViews(getPackageName(),R.layout.pullnotice);// contentView.setImageViewResource(R.id.pullnoti,R.drawable.icon);// contentView.setTextViewText(R.id.text,content);// n.contentView=contentView;
这也是通知下拉时候的样式,这个是自定义的一个样式,可以在xml中定义好样式,<span style="font-family: Arial, Helvetica, sans-serif;">R.id.pullnoti是</span><span style="font-family: Arial, Helvetica, sans-serif;">R.layout.pullnotice当中的ImageView</span>
<span style="font-family: Arial, Helvetica, sans-serif;"></span><pre name="code" class="java">R.id.text是<span style="font-family: Arial, Helvetica, sans-serif;">R.layout.pullnotice当中的一个TextView</span>

0 0
原创粉丝点击