我正在开发一个应用程序,在该应用程序中我不必为notification
. 相反,我必须programmatically
为RemoteViews
. 这是我正在为布局做的事情:
Notification notify = new Notification.Builder(context)
.setContentTitle("Notification")
.setLargeIcon(
decodeBase64(NotificationImages.notification_ic_stat_notify))
.build();
LinearLayout linLayout = new LinearLayout(context);
@SuppressWarnings("deprecation")
Drawable bg = new BitmapDrawable(
decodeBase64(NotificationImages.search_bg));
linLayout.setOrientation(LinearLayout.HORIZONTAL);
linLayout.setBackground(bg);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
linLayout.setLayoutParams(llp);
ImageView icon = new ImageView(context);
@SuppressWarnings("deprecation")
Drawable icon_bg = new BitmapDrawable(
decodeBase64(NotificationImages.notification_logo));
icon.setBackground(icon_bg);
LinearLayout.LayoutParams image_lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
image_lp.setMargins(20, 0, 0, 0);
image_lp.gravity = Gravity.CENTER_VERTICAL;
icon.setLayoutParams(image_lp);
linLayout.addView(icon);
忽略base64
解码的使用,这是我出于某种随机目的而做的。所以,现在我想要添加这个layout
以RemoteViews
在notification panel
. 像这样的东西:
RemoteViews contentView = new RemoteViews(PACKAGE_NAME,
R.layout.persistent_notification_layout);
如何,我可以layout.persistent_notification_layout
从以编程方式创建的布局中替换?任何形式的帮助将不胜感激。