Dan*_*l.B 9 notifications android
我对 Android 通知模板有多个问题。据我所知,在以前的 Android 版本中,大图标位于左侧,从 Android 7 开始,它们被移到了右侧。在我的所有设备(android 8-10)上,大图标确实位于右侧。但在本文档中,在“Wear OS 设备”部分中有一个通知,左侧有一个大图标,右下角有一个小图标。也在同一张图像上,最后一个通知,看起来像它的左右有两个大图标,对吗?最近我在 android 10 上看到一些应用程序的通知图标移到了左侧,而在 android 11 上则看到了左右大图(看截图)。所以我的问题是:
https://developer.android.com/guide/topics/ui/notifiers/notifications#compatibility
我认为要显示左右图标(其中一个很重要),您可以在setStyle(...)构建器方法中添加大图标来设置大图标和小图标。请尝试使用以下代码片段来解决您的问题。谢谢
// Create the left and right large icons
Bitmap leftIcon = BitmapFactory.decodeResource(getResources(), R.drawable.<left_large_icon>);
Bitmap rightIcon = BitmapFactory.decodeResource(getResources(), R.drawable.<right_large_icon>);
// Create the notification
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.small_icon)
.setContentTitle("Notification Title")
.setContentText("Notification Text")
.setLargeIcon(leftIcon)
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(rightIcon)
.bigLargeIcon(null)) // or if you need any
.setContentIntent(pendingIntent)
.setAutoCancel(true);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1037 次 |
| 最近记录: |