Android 创建自己的通知样式

Android 创建自己的通知样式,android,android-notifications,android-notification-bar,Android,Android Notifications,Android Notification Bar,在我的Android应用程序中,我想创建一个可消耗的通知。为此,我必须为通知设置如下样式: NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(android.R.drawable.ic_menu_info_details); builder.setContentTitle("My notification"); builder.setContentTex

在我的Android应用程序中,我想创建一个可消耗的通知。为此,我必须为通知设置如下样式:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

builder.setSmallIcon(android.R.drawable.ic_menu_info_details);
builder.setContentTitle("My notification");
builder.setContentText("Hello World!");

builder.setStyle(...);
Android给了我一些样式,我可以使用这个方法,但我喜欢创建自己的样式,这样我就可以在通知中加载布局。那我该怎么做呢?如果我创建
Style
的子类,则只有以下两种方法:

public Notification build();
public void setBuilder(Builder builder);

那么,如何在通知中加载自己的布局呢
builder.setContent对我来说是不够的,因为那时我的布局只有64dp。

找到了解决此问题的方法。这真的很容易。只需在此处使用此代码:

String packageName = this.getPackageName();
RemoteViews bigView = new RemoteViews(packageName, R.layout.test);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(android.R.drawable.ic_menu_info_details);
builder.setContentTitle("My notification");
builder.setContentText("Hello World!");

Notification noti = builder.build();
noti.bigContentView = bigView;

NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mgr.notify(1234, noti);