如何制作自定义通知?

How can I make a custom Notification?

这两天我一直在努力寻找一种方法来制作自定义 android 通知。我已经通过了远程视图解决方案,但该解决方案仅限于仅更改布局。我需要的是在通知中放置一个自定义视图(文本视图、图像视图和这些通常在通知中看到的典型视图除外)。这可能吗?

but this solution is very limited to changing the layout only

我不知道你这是什么意思。 RemoteViews 当然可以有多个布局管理器(例如 LinearLayout);否则就没有意义了。

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?

欢迎您尝试 RemoteViews 支持的任何内容,但不包括 AdapterView 子类(例如 ListView)。交互式小部件(例如按钮)将不可靠,特别是在 Android 1.x/2.x 上,因为供应商对通知托盘的自定义有时会阻止交互式小部件正常工作。

最简单的自定义通知示例

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());

 }

要显示自定义通知时调用此函数。