<1>.直接定义notification,并启动
RemoteViews mRemoteViews=new RemoteViews(getPackageName(),R.layout.remoteview_layout);
//2.构建一个打开Activity的PendingIntent
Intent intent=newIntent(context,xxx.class);
PendingIntent mPendingIntent=PendingIntent.getActivity(context,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
//3.创建一个Notification
mNotification=newNotification.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(mPendingIntent)
.setContent(mRemoteViews)
.setAutoCancel(true)
.build();
//4.获取NotificationManager
manager= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(2,mNotification);
1.获取布局
通过
RemoteViews mRemoteViews=newRemoteViews(getPackageName(),R.layout.remoteview_layout);
用来获取自定义的RemoteView布局,
2.设置布局
通过notification的setContent(mRemoteViews)设置内容
3.接下来就可展示提示
<2> xml布局文件R.layout.remoteview_layout
根据需求写的一个layout布局即可.
但是需要注意,RemoteView并不支持所有view类型,支持类型有
Layout:
FrameLayout,LineraLayout,RelativeLayout,GridLayout
View:
AnalogClock,Button,Chronometer,ImageButton,ImageView,ProgressBar,TextView,ViewFlipper,ListView,GridView,StackView,AdapterViewFlipper,ViewStub