自定义Notification高视图锁屏显示不全

view = new RemoteViews(this.getPackageName(), R.layout.layout_nootification);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);

    mBuilder.setSmallIcon(R.mipmap.d3switch_on);
    mBuilder.setTicker("");

             notification = mBuilder.build();
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notification.flags |= Notification.FLAG_NO_CLEAR;
    notification.priority = Notification.PRIORITY_MAX;
    notification.bigContentView = view;
    notificationManager.notify(1, notification);

            锁屏状态只显示默认通知栏的高度 视图也不是自定义的 就只有设置的哪个图标
            必须的下拉一下显示的这个通知栏才会正常显示
            怎么设置 在锁屏状态正常显示自定义的高视图

以上我们得到了自定义的RemoteViews。通过下面这段代码就能生成自定义View的Notification,注意这里使用了setContent()方法。这是网上自定义Notification都会使用的方法。

Notification notification = new NotificationCompat.Builder(context).setContent(remoteViews).build();
但是它会有一个问题。

通过setContent()方法获得的Notification是定高的。如果View的高度比默认高度要大的话,就有一部分显示不出来。如下图

默认情况下通知高度为64dp,当然Rom不同可能会有些区别。一般文字在小于两行的情况下都是可以显示。

那么如何做到wrap_content。需要使用一些黑科技。如下:

NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
if(android.os.Build.VERSION.SDK_INT >= 16) {
notification = builder.build();
notification.bigContentView = remoteViews;
}
notification.contentView = remoteViews;
引用来自https://www.cnblogs.com/dongweiq/p/5407815.html