[英]How can I make a custom Notification?
I have been struggling in these last two days to find a way to make a custom android notification. 最近两天我一直在努力寻找一种方法来制作自定义的android通知。 I have passed by the remote views solution but this solution is very limited to changing the layout only.
我已经通过了远程视图解决方案,但是该解决方案仅限于更改布局。 What I need is to put a custom view(other than text views, image views, and these typical views that are usually seen in a notification) in a notification.
我需要在通知中放入自定义视图(文本视图,图像视图以及通常在通知中看到的这些典型视图除外)。 Is that possible?
那可能吗?
but this solution is very limited to changing the layout only
但是此解决方案仅限于更改布局
I do not know what you mean by this. 我不知道你是什么意思。 The
RemoteViews
can certainly have more than a layout manager (eg, LinearLayout
); 当然,
RemoteViews
可以拥有的不仅仅是布局管理器(例如LinearLayout
); otherwise, it would pointless. 否则,将毫无意义。
What I need is to put a custom view(other than text views, image views, and these typical views that are usually seen in a notification) in a notification.
我需要在通知中放入自定义视图(文本视图,图像视图以及通常在通知中看到的这些典型视图除外)。 Is that possible?
那可能吗?
You are welcome to try whatever RemoteViews
supports, minus the AdapterView
subclasses (eg, ListView
). 欢迎您尝试使用
RemoteViews
支持的任何方法,减去AdapterView
子类(例如ListView
)。 Interactive widgets, such as buttons, will be unreliable, particularly on Android 1.x/2.x, as vendor customizations to the notification tray sometimes prevent interactive widgets from working properly. 交互式小部件(例如按钮)将不可靠,尤其是在Android 1.x / 2.x上,因为供应商对通知托盘的自定义有时会阻止交互式小部件正常工作。
A simplest example of custom notification 自定义通知的最简单示例
private void showCustomeNoti() { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( this).setSmallIcon(R.drawable.ic_launcher); RemoteViews mContentView = new RemoteViews(getPackageName(), R.layout.custome_notification_layout); mBuilder.setContent(mContentView); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(100, mBuilder.build()); }
Call this function when you want to show custom notification. 要显示自定义通知时,请调用此函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.