android - 安卓最大。自定义通知的大小
问题描述
我正在尝试为我的应用创建一些自定义通知。
通常折叠视图布局限制为 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)
结果如下:
现在的问题是:我是否以某种方式失败了实施?如果没有,有没有办法找出最大值。以编程方式当前手机的通知高度?
解决方案
Notification
您看到的(您的RemoteView
)是由另一个进程创建的,只有该进程才能知道大小
没有官方方法可以获取自定义通知的最大高度。我认为你能做的唯一方法是减小文本大小
推荐阅读
- javascript - 为什么我的 v-speed-dial 不与 Vue 页面上的其他组件重叠?
- javascript - 如何在我的 React JS 应用程序中显示常规 javascript?
- sql-server - SSIS 包在切换到不保存敏感文件后不起作用
- scala - 如何使用 sbt-native-packager 在 Docker 中使二进制文件可执行?
- apache - 来自 mod_rewrite 的 RewriteRule 仅可用作添加 http://%{HTTP_HOST} 的重定向,但没有它根本无法工作
- symfony - Symfony 4+ 表单验证在控制器操作中完成?
- reactjs - CORS 仅在 Firefox 和 Safari 上阻止内容且仅 onClick()
- react-native - 是否可以从 createStackNavigator 导航到 createDrawerNavigator?
- c# - 正确处理来自 C#/Java 应用程序的 OCSP 请求(+ BouncyCastle)
- html - 加载文本后,无法让 div 扩展到另一个 div 的高度