【问题标题】:Android max. size of custom notification安卓最大。自定义通知的大小
【发布时间】:2019-06-22 08:19:57
【问题描述】:

我正在尝试为我的应用创建一些自定义通知。

通常折叠视图布局限制为 64 dp,展开视图布局限制为 256 dp。

尽管我考虑了这些限制,但您可以在下面的屏幕截图中看到,通知似乎在几部手机上都被切断了。 我对此进行了一些研究,因为我认为根据不同的制造商或 UI 也有限制,但找不到任何东西。

就是这样实现的:

// 64dp is set for height
val collapsedView = RemoteViews(packageName, R.layout.custom_notification_collapsed)
// 256dp is set for height
val expandedView = RemoteViews(packageName, R.layout.custom_notification_expanded)

val customNotification: Notification = NotificationCompat.Builder(this, "default")
        .setSmallIcon(R.drawable.ic_launcher_background)
        .addAction(R.drawable.ic_map, "Personal", PendingIntent.getService(this, 0, personalIntent, PendingIntent.FLAG_UPDATE_CURRENT))
        .addAction(R.drawable.ic_map, "Business", PendingIntent.getService(this, 0, businessIntent, PendingIntent.FLAG_UPDATE_CURRENT))
        .addAction(R.drawable.ic_map, "Work", PendingIntent.getService(this, 0, businessIntent, PendingIntent.FLAG_UPDATE_CURRENT))
        .setColor(Color.parseColor("#00D8FF"))
        .setStyle(NotificationCompat.DecoratedCustomViewStyle())
        .setCustomContentView(collapsedView)
        .setCustomBigContentView(expandedView)
        .build()

notificationManager.notify(4, customNotification)

结果如下:

Xiaomi Mi Mix2

Samsung Galaxy Note 8

现在的问题是: 我是否以某种方式失败了实施? 如果没有,有没有办法找出最大值。以编程方式获取当前手机的通知高度?

【问题讨论】:

    标签: android kotlin notifications height


    【解决方案1】:

    由于您正在添加的操作,它们被切断了 尝试删除您将获得完整 256/64 dp 的操作。

    【讨论】:

      【解决方案2】:

      你看到的Notification(你的RemoteView)是由另一个进程创建的,只有那个进程才能知道大小

      没有官方方法可以获取自定义通知的最大高度。我认为您可以做的唯一方法是减小文本大小

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-09
        • 1970-01-01
        • 2015-01-19
        • 1970-01-01
        • 2011-04-22
        • 1970-01-01
        相关资源
        最近更新 更多