我试图使我的自定义通知类似于这一个
我发现了一堆类似的问题在这里和互联网上的例子,但没有人帮助我。在android中的大自定义通知
这里是我的代码:
RemoteViews bigView = new RemoteViews(mContext.getApplicationContext().getPackageName(), R.layout.notification_playback);
Intent i = new Intent(MainActivity.ACTION_PLAYER, null, mContext, MainActivity.class);
i.putExtra("CURRENT_TRACK", t);
i.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pi = PendingIntent.getActivity(mContext, 0, i, 0);
Notification n = new NotificationCompat.Builder(mContext)
.setContentTitle(t.getName())
.setContentText(t.getArtistName())
.setContentIntent(pi)
.setSmallIcon(R.drawable.ic_notification)
.setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_launcher))
.setOngoing(true)
.setContent(bigView)
.setWhen(System.currentTimeMillis())
.build();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
n.bigContentView = bigView;
NotificationManager notifyMgr = (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notifyMgr.notify(0, n);
它出现在默认的大小,成为大小我只后,就可以长按预期。
是否可以在不长时间使其立即变大尺寸?如果有,我该怎么办? 谢谢!
+0
这是[另一个问题](http://stackoverflow.com/questions/21237495/create-custom-big-notifications),可能会帮助你。 –
2014-10-29 13:20:21
+0
@TheRealBenjamin谢谢,但我已经试过了。它说'技巧不是使用setStyle(),而是在构建它之后手动设置Notification的bigContentView字段,但正如你所看到的,我正在做这件事。 –
2014-10-29 13:25:18
+1
http://stackoverflow.com/questions/18367631/change-notification-layout –
2014-10-29 13:29:53