首先需要用到三个类:RemoteViews,NotificationCompat.Builder,NotificationManager
RemoteViews view = new RemoteViews(mContext.getPackageName(),R.layout.icon_notification);
NotificationCompat.Builder notificationB = new NotificationCompat.Builder(mContext);
NotificationManager notificationM = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationB.setSmallIcon(R.mipmap.ic_launcher);
view.setImageViewResource(R.id.img_icon,R.mipmap.ic_launcher);
view.setTextViewText(R.id.tv_title,"英雄联盟联赛");
view.setTextViewText(R.id.tv_content,"您关注的战队正在比赛哦");
notificationB.setContent(view);
notificationM.notify(3,notificationB.build());
实例化一个RemoteViews,传入两个参数,包名和自定义的布局ID。
通过NotificationCompat.builder 设置setSmallIcon(必须有)
remoteview设置布局
NotificationManager启动通知
参考http://www.jianshu.com/p/33e979ba6be1