【问题标题】:How to increase the height of remoteview in android notification如何在android通知中增加remoteview的高度
【发布时间】:2014-07-21 00:48:22
【问题描述】:

我正在尝试使用自定义 RemoteView 创建通知。但是在显示通知时,RemoteView 的底部被裁剪了。通知中只有一半的远程视图可见。谁能告诉我增加通知的高度在安卓中?

【问题讨论】:

    标签: android android-layout statusbar android-notifications


    【解决方案1】:

    首先,Android 上的通知高度限制为 256dp。超过此高度的视图将被剪裁在底部。其次,要创建自定义大通知布局,请像这样使用 RemoteView:

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setSmallIcon(R.drawable.ic_notification_icon)
    
        RemoteViews content = new RemoteViews(this.getPackageName(), R.layout.content);
    
        Notification notif = builder.build();
        notif.bigContentView = content;
        notificationManager.notify(NOTIFICATION_ID, notif);
    

    【讨论】:

    • .bigContentView 已弃用,还有其他方法可以做这种事情吗?
    • 解决了这个问题:mBuilder.setCustomBigContentView(getComplexNotificationView()); Notification.Builder 有这个设置 bigContentView 的方法
    • @LuigiBlu 通过使用这个如果我展开通知,那么只显示我的自定义视图,否则不显示自定义视图。我想要默认的自定义视图。
    【解决方案2】:

    将通知意图的样式设置为bigstyle,

    Notification noti = new Notification.Builder(this).setStyle(new Notification.BigTextStyle().bigText(longText)) 
    

    【讨论】:

    • 如果我想使用自定义布局来通知怎么办
    • 我建议已经实现了和你一样的,但是它有一个最大的显示高度。因为我的布局很大,元素的底部被剪掉了。
    • @Sagar Patil,您好。你找到解决问题的决定了吗?我也有同样的烦恼
    • 我也有同样的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-23
    • 1970-01-01
    • 2012-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多