美文网首页
使用RemoteView自定义通知栏

使用RemoteView自定义通知栏

作者: 牙膏很好吃 | 来源:发表于2018-10-08 19:12 被阅读0次

<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

类似EditText就不支持

相关文章

网友评论

      本文标题:使用RemoteView自定义通知栏

      本文链接:https://www.haomeiwen.com/subject/wblwkxtx.html