Android:折叠通知中的额外间距
我正在使用折叠和展开的视图发出持久通知。但是我的折叠视图在底部占用了额外的空间。这不是一个布局问题,我知道了 最初,我为展开视图和折叠视图创建了一个单独的布局,但我意识到我需要通知标题的默认设计,所以我删除了折叠视图布局Android:折叠通知中的额外间距,android,android-layout,push-notification,notifications,Android,Android Layout,Push Notification,Notifications,我正在使用折叠和展开的视图发出持久通知。但是我的折叠视图在底部占用了额外的空间。这不是一个布局问题,我知道了 最初,我为展开视图和折叠视图创建了一个单独的布局,但我意识到我需要通知标题的默认设计,所以我删除了折叠视图布局 mBuilder.setSmallIcon(R.drawable.ic_fix_icon) .setAutoCancel(false) .setOngoing(true) .setS
mBuilder.setSmallIcon(R.drawable.ic_fix_icon)
.setAutoCancel(false)
.setOngoing(true)
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setCustomBigContentView(remoteExpandedViews)
.setPriority(Notification.PRIORITY_MAX)
.setChannelId(NOTIFICATION_CHANNEL_ID);
请在下面找到我用于扩展通知视图的布局文件。我不会对折叠视图使用任何布局。我想要一个标题,描述和两个按钮在我的扩展通知。从两个按钮单击,我直接打开活动
removeExpandedViews.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_margin="0dp"
android:padding="0dp"
android:background="@android:color/transparent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/custome_expanded_notification_relativelayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/custome_expanded_notification_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/TextAppearance.Compat.Notification.Info"
android:text="Today's task"
android:fontFamily="@font/robotomedium"
android:ellipsize="end"
android:textColor="@color/gray"
android:textSize="12sp"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_alignParentLeft="true"/>
<ImageView
android:id="@+id/custome_expanded_notification_next_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/ic_next_icon"
android:tint="@color/black"
android:visibility="gone"
android:padding="10dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"/>
<TextView
android:id="@+id/custome_expanded_notification_task"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No task for today !"
android:ellipsize="end"
android:textSize="14sp"
android:layout_marginTop="2dp"
android:textColor="@color/black"
android:layout_marginLeft="5dp"
android:layout_toLeftOf="@+id/custome_expanded_notification_next_icon"
style="@style/TextAppearance.Compat.Notification.Title"
android:fontFamily="@font/robotomedium"
android:layout_below="@+id/custome_expanded_notification_title"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/custome_expanded_notification_relativelayout1"
android:padding="0dp"
android:layout_marginLeft="5dp">
<TextView
android:id="@+id/custome_expanded_notification_add_task"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Task"
android:padding="0dp"
android:textStyle="bold"
android:textAllCaps="true"
android:textColor="@color/textColorTitle"
android:fontFamily="@font/robotobold"
android:textSize="11dp"
android:layout_marginTop="10dp"
android:gravity="center"/>
<TextView
android:id="@+id/custome_expanded_notification_setting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Setting"
android:textStyle="bold"
android:padding="0dp"
android:textAllCaps="true"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@+id/custome_expanded_notification_add_task"
android:textColor="@color/textColorTitle"
android:fontFamily="@font/robotobold"
android:textSize="11dp"
android:layout_marginTop="10dp"
android:gravity="center"/>
</RelativeLayout>
</RelativeLayout>
我想像任何人一样。做折叠视图。
我看到您的通知小图标是77*77像素。根据安卓关于通知小图标的指导原则,你的图标大小不应超过24*24像素
也要考虑自定义布局的嵌套。p> 你能换一下尺寸用一下吗。如果这对你不起作用,请告诉我
编辑: 使用Android Studio中的图像资源:使用这个,它肯定会起作用
NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_NONE);
chan.setLightColor(Color.BLUE);
chan.setImportance(NotificationManager.IMPORTANCE_UNSPECIFIED);
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
使用uiautomatorviewer检查UI层次结构,并查看它为您的通知而增加的附加视图。您好,请同时粘贴您的
ic_fix_图标
和remoteExpandedViews
?@ravi请检查。我只使用24X24图标,它仍然显示额外的间距。您是否使用了Android Studio中的添加图像资源并将图标类型设置为通知?是的。我也这么做了。最后一件事,您没有在生成器上调用setCustomContentView(RemoteViews RemoteView)
。这是有意的吗?通常,对于自定义大内容视图,也会使用自定义内容视图。您不希望通知有任何最小化视图。如果您不希望任何最小化视图,请尝试在构建器上添加setCustomContentView(null)
,或者添加自定义布局并将其传递给相同的视图。我们得到一个错误java.lang.IllegalArgumentException:重要性级别无效