Android:折叠通知中的额外间距
Android: Extra spacing in collapsed notification
我正在使用折叠和展开视图发出持久通知。但是我的折叠视图在底部占用了额外的 space。这不是我想出来的布局问题。
最初,我为展开视图和折叠视图创建了一个单独的布局,但我意识到我需要通知的默认设计header,所以我删除了折叠视图布局。
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>
我想要 any.do 折叠视图。
我看到你的通知小图标是77*77 px。根据android关于通知小图标的规定,你的图标不能超过24*24像素。
还要考虑减少自定义布局的嵌套。 :)
能不能换个尺寸用一下。如果这对您不起作用,请告诉我。
编辑:
使用来自 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);
我正在使用折叠和展开视图发出持久通知。但是我的折叠视图在底部占用了额外的 space。这不是我想出来的布局问题。
最初,我为展开视图和折叠视图创建了一个单独的布局,但我意识到我需要通知的默认设计header,所以我删除了折叠视图布局。
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>
我想要 any.do 折叠视图。
我看到你的通知小图标是77*77 px。根据android关于通知小图标的规定,你的图标不能超过24*24像素。
还要考虑减少自定义布局的嵌套。 :)
能不能换个尺寸用一下。如果这对您不起作用,请告诉我。
编辑:
使用来自 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);